diff --git a/build/cocos2d-jsb-samples.wp8.sln b/build/cocos2d-jsb-samples.wp8.sln new file mode 100644 index 0000000000..cdb151b72b --- /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", "js-moonwarriors", "{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", "js-tests", "{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..042bd304f5 100644 --- a/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj +++ b/build/cocos2d_jsb_samples.xcodeproj/project.pbxproj @@ -97,6 +97,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 */; }; @@ -420,6 +424,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; }; @@ -678,6 +686,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 */, @@ -1226,6 +1238,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 +1252,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; diff --git a/frameworks/cocos2d-html5 b/frameworks/cocos2d-html5 index dc8258ba9f..f0311f25c3 160000 --- a/frameworks/cocos2d-html5 +++ b/frameworks/cocos2d-html5 @@ -1 +1 @@ -Subproject commit dc8258ba9f42a20027caad97245d3b2114e036a9 +Subproject commit f0311f25c3c37d180caa1b9f799478d8106aa2b5 diff --git a/frameworks/js-bindings/bindings/Android.mk b/frameworks/js-bindings/bindings/Android.mk index 05ed968216..fcb734f895 100644 --- a/frameworks/js-bindings/bindings/Android.mk +++ b/frameworks/js-bindings/bindings/Android.mk @@ -12,6 +12,7 @@ LOCAL_SRC_FILES := auto/jsb_cocos2dx_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 \ manual/ScriptingCore.cpp \ manual/cocos2d_specifics.cpp \ manual/js_manual_conversions.cpp \ @@ -36,7 +37,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 diff --git a/frameworks/js-bindings/bindings/CMakeLists.txt b/frameworks/js-bindings/bindings/CMakeLists.txt index 99412812a0..7691e0f74e 100644 --- a/frameworks/js-bindings/bindings/CMakeLists.txt +++ b/frameworks/js-bindings/bindings/CMakeLists.txt @@ -38,6 +38,7 @@ 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 manual/ScriptingCore.cpp manual/cocos2d_specifics.cpp manual/js_manual_conversions.cpp @@ -62,6 +63,7 @@ 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 ) 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..e90029909c --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -0,0 +1,1075 @@ +/** + * @module cocos2dx_3d + */ +var cc = cc || {}; + +/** + * @class Skeleton3D + */ +cc.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 + */ +cc.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 init + * @return {bool} + */ +init : function ( +) +{ + return false; +}, + +/** + * @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 + */ +cc.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 + */ +cc.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 calcuateAABB + */ +calcuateAABB : function ( +) +{ +}, + +/** + * @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 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 + */ +cc.Animation3D = { + +/** + * @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 + */ +cc.Animate3D = { + +/** + * @method getSpeed + * @return {float} + */ +getSpeed : function ( +) +{ + return 0; +}, + +/** + * @method removeFromMap + */ +removeFromMap : function ( +) +{ +}, + +/** + * @method setWeight + * @param {float} arg0 + */ +setWeight : function ( +float +) +{ +}, + +/** + * @method getOriginInterval + * @return {float} + */ +getOriginInterval : function ( +) +{ + return 0; +}, + +/** + * @method setSpeed + * @param {float} arg0 + */ +setSpeed : function ( +float +) +{ +}, + +/** + * @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 Animate3D + * @constructor + */ +Animate3D : function ( +) +{ +}, + +}; + +/** + * @class AttachNode + */ +cc.AttachNode = { + +/** + * @method create + * @param {cc.Bone3D} arg0 + * @return {cc.AttachNode} + */ +create : function ( +bone3d +) +{ + return cc.AttachNode; +}, + +/** + * @method AttachNode + * @constructor + */ +AttachNode : function ( +) +{ +}, + +}; + +/** + * @class BillBoard + */ +cc.BillBoard = { + +/** + * @method getMode + * @return {cc.BillBoard::Mode} + */ +getMode : function ( +) +{ + return 0; +}, + +/** + * @method visit + * @param {cc.Renderer} arg0 + * @param {mat4_object} arg1 + * @param {unsigned int} arg2 + */ +visit : function ( +renderer, +mat4, +int +) +{ +}, + +/** + * @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_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js index e629f1c543..b08ee3e4c2 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 @@ -1058,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; }, /** @@ -1224,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; }, /** @@ -1274,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; }, /** @@ -1435,6 +1435,16 @@ getChildrenCount : function ( return 0; }, +/** + * @method getNodeToParentTransform + * @return {mat4_object} + */ +getNodeToParentTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method convertToNodeSpaceAR * @param {vec2_object} arg0 @@ -1515,6 +1525,16 @@ getAnchorPointInPoints : function ( return cc.Vec2; }, +/** + * @method getRotationQuat + * @return {cc.Quaternion} + */ +getRotationQuat : function ( +) +{ + return cc.Quaternion; +}, + /** * @method removeChildByName * @param {String} arg0 @@ -1649,16 +1669,6 @@ str { }, -/** - * @method setAdditionalTransform -* @param {cc.AffineTransform|mat4_object} affinetransform -*/ -setAdditionalTransform : function( -mat4 -) -{ -}, - /** * @method updatePhysicsBodyTransform * @param {mat4_object} arg0 @@ -1705,16 +1715,6 @@ getScheduler : function( return cc.Scheduler; }, -/** - * @method getParentToNodeAffineTransform - * @return {cc.AffineTransform} - */ -getParentToNodeAffineTransform : function ( -) -{ - return cc.AffineTransform; -}, - /** * @method getOrderOfArrival * @return {int} @@ -1768,6 +1768,16 @@ getParent : function( return cc.Node; }, +/** + * @method getWorldToNodeTransform + * @return {mat4_object} + */ +getWorldToNodeTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method getPositionY * @return {float} @@ -1831,13 +1841,13 @@ bool }, /** - * @method getParentToNodeTransform - * @return {mat4_object} + * @method getParentToNodeAffineTransform + * @return {cc.AffineTransform} */ -getParentToNodeTransform : function ( +getParentToNodeAffineTransform : function ( ) { - return cc.Mat4; + return cc.AffineTransform; }, /** @@ -1944,16 +1954,6 @@ int { }, -/** - * @method getWorldToNodeAffineTransform - * @return {cc.AffineTransform} - */ -getWorldToNodeAffineTransform : function ( -) -{ - return cc.AffineTransform; -}, - /** * @method setCascadeColorEnabled * @param {bool} arg0 @@ -2129,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; }, /** @@ -2158,6 +2158,16 @@ getNormalizedPosition : function ( return cc.Vec2; }, +/** + * @method getParentToNodeTransform + * @return {mat4_object} + */ +getParentToNodeTransform : function ( +) +{ + return cc.Mat4; +}, + /** * @method convertToNodeSpace * @param {vec2_object} arg0 @@ -2191,13 +2201,13 @@ isCascadeColorEnabled : function ( }, /** - * @method isOpacityModifyRGB - * @return {bool} + * @method setRotationQuat + * @param {cc.Quaternion} arg0 */ -isOpacityModifyRGB : function ( +setRotationQuat : function ( +quaternion ) { - return false; }, /** @@ -10341,26 +10351,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} @@ -18504,18 +18494,6 @@ vec3 { }, -/** - * @method isVisibleInFrustum - * @param {cc.AABB} arg0 - * @return {bool} - */ -isVisibleInFrustum : function ( -aabb -) -{ - return false; -}, - /** * @method setCameraFlag * @param {cc.CameraFlag} arg0 @@ -18659,6 +18637,371 @@ 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 + */ +setLightFlag : function ( +lightflag +) +{ +}, + +/** + * @method setIntensity + * @param {float} arg0 + */ +setIntensity : function ( +float +) +{ +}, + +/** + * @method getLightFlag + * @return {cc.LightFlag} + */ +getLightFlag : function ( +) +{ + return 0; +}, + +}; + +/** + * @class DirectionLight + */ +cc.DirectionLight = { + +/** + * @method getDirection + * @return {vec3_object} + */ +getDirection : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method getDirectionInWorld + * @return {vec3_object} + */ +getDirectionInWorld : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method setDirection + * @param {vec3_object} arg0 + */ +setDirection : function ( +vec3 +) +{ +}, + +/** + * @method create + * @param {vec3_object} arg0 + * @param {color3b_object} arg1 + * @return {cc.DirectionLight} + */ +create : function ( +vec3, +color3b +) +{ + return cc.DirectionLight; +}, + +/** + * @method DirectionLight + * @constructor + */ +DirectionLight : function ( +) +{ +}, + +}; + +/** + * @class PointLight + */ +cc.PointLight = { + +/** + * @method getRange + * @return {float} + */ +getRange : function ( +) +{ + return 0; +}, + +/** + * @method setRange + * @param {float} arg0 + */ +setRange : function ( +float +) +{ +}, + +/** + * @method create + * @param {vec3_object} arg0 + * @param {color3b_object} arg1 + * @param {float} arg2 + * @return {point_object} + */ +create : function ( +vec3, +color3b, +float +) +{ + return cc.PointLight; +}, + +/** + * @method PointLight + * @constructor + */ +PointLight : function ( +) +{ +}, + +}; + +/** + * @class SpotLight + */ +cc.SpotLight = { + +/** + * @method getRange + * @return {float} + */ +getRange : function ( +) +{ + return 0; +}, + +/** + * @method setDirection + * @param {vec3_object} arg0 + */ +setDirection : function ( +vec3 +) +{ +}, + +/** + * @method getCosInnerAngle + * @return {float} + */ +getCosInnerAngle : function ( +) +{ + return 0; +}, + +/** + * @method getOuterAngle + * @return {float} + */ +getOuterAngle : function ( +) +{ + return 0; +}, + +/** + * @method getInnerAngle + * @return {float} + */ +getInnerAngle : function ( +) +{ + return 0; +}, + +/** + * @method getDirection + * @return {vec3_object} + */ +getDirection : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method getCosOuterAngle + * @return {float} + */ +getCosOuterAngle : function ( +) +{ + return 0; +}, + +/** + * @method setOuterAngle + * @param {float} arg0 + */ +setOuterAngle : function ( +float +) +{ +}, + +/** + * @method setInnerAngle + * @param {float} arg0 + */ +setInnerAngle : function ( +float +) +{ +}, + +/** + * @method getDirectionInWorld + * @return {vec3_object} + */ +getDirectionInWorld : function ( +) +{ + return cc.Vec3; +}, + +/** + * @method setRange + * @param {float} arg0 + */ +setRange : function ( +float +) +{ +}, + +/** + * @method create + * @param {vec3_object} arg0 + * @param {vec3_object} arg1 + * @param {color3b_object} arg2 + * @param {float} arg3 + * @param {float} arg4 + * @param {float} arg5 + * @return {cc.SpotLight} + */ +create : function ( +vec3, +vec3, +color3b, +float, +float, +float +) +{ + return cc.SpotLight; +}, + +/** + * @method SpotLight + * @constructor + */ +SpotLight : function ( +) +{ +}, + +}; + +/** + * @class AmbientLight + */ +cc.AmbientLight = { + +/** + * @method create + * @param {color3b_object} arg0 + * @return {cc.AmbientLight} + */ +create : function ( +color3b +) +{ + return cc.AmbientLight; +}, + +/** + * @method AmbientLight + * @constructor + */ +AmbientLight : function ( +) +{ +}, + +}; + /** * @class GLProgram */ @@ -21336,3 +21679,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/jsb_cocos2dx_3d_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.cpp new file mode 100644 index 0000000000..ecebec0770 --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -0,0 +1,3141 @@ +#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_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::Sprite3D* cobj = (cocos2d::Sprite3D *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_3d_Sprite3D_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_3d_Sprite3D_init : wrong number of arguments: %d, was expecting %d", argc, 0); + 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("init", js_cocos2dx_3d_Sprite3D_init, 0, 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_calcuateAABB(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_calcuateAABB : Invalid Native Object"); + if (argc == 0) { + cobj->calcuateAABB(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_Mesh_calcuateAABB : 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_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("calcuateAABB", js_cocos2dx_3d_Mesh_calcuateAABB, 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("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_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("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_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_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_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("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("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_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_visit(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_visit : Invalid Native Object"); + if (argc == 3) { + cocos2d::Renderer* arg0; + cocos2d::Mat4 arg1; + unsigned 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::Renderer*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= jsval_to_matrix(cx, args.get(1), &arg1); + ok &= jsval_to_uint32(cx, args.get(2), &arg2); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_BillBoard_visit : Error processing arguments"); + cobj->visit(arg0, arg1, arg2); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_3d_BillBoard_visit : wrong number of arguments: %d, was expecting %d", argc, 3); + 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("visit", js_cocos2dx_3d_BillBoard_visit, 3, 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, "cc", &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..9b0a94e614 --- /dev/null +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -0,0 +1,167 @@ +#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_init(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_calcuateAABB(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_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_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_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_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_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_visit(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_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp index a018658187..0095a616b6 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, @@ -1885,12 +1953,12 @@ 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"); @@ -1898,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); @@ -1919,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); @@ -1937,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); @@ -1961,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); @@ -1986,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"); @@ -1999,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"); @@ -2010,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); @@ -2018,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); @@ -2033,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; } @@ -2060,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"); @@ -2075,7 +2144,7 @@ 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; } @@ -2084,20 +2153,20 @@ bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_updateTransformFromPhysics(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_updateTransformFromPhysics : 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_Node_updateTransformFromPhysics : Error processing arguments"); cobj->updateTransformFromPhysics(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2106,7 +2175,8 @@ bool js_cocos2dx_Node_updateTransformFromPhysics(JSContext *cx, uint32_t argc, j } 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"); @@ -2114,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; } @@ -2123,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; } @@ -2143,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; } @@ -2163,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"); @@ -2177,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); @@ -2187,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); @@ -2197,22 +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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2227,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; } @@ -2236,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; } @@ -2258,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"); @@ -2266,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; } @@ -2275,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; @@ -2295,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; } @@ -2304,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; } @@ -2324,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"); @@ -2332,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; } @@ -2341,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"); @@ -2349,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; } @@ -2358,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; } @@ -2378,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; } @@ -2398,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; } @@ -2418,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; } @@ -2438,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"); @@ -2446,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; } @@ -2455,22 +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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2485,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; } @@ -2494,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; } @@ -2509,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; } @@ -2524,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"); @@ -2532,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; } @@ -2541,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; } @@ -2571,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"); @@ -2579,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; } @@ -2588,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"); @@ -2596,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"); @@ -2647,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; } @@ -2656,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; } @@ -2700,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; } @@ -2722,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"); @@ -2737,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; } @@ -2746,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"); @@ -2761,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; } @@ -2770,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; } @@ -2790,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; } @@ -2817,22 +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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2847,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; } @@ -2856,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; } @@ -2876,22 +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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -2906,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; } @@ -2915,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"); @@ -2935,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; } @@ -2944,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); @@ -2966,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); @@ -2976,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"); @@ -2984,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; } @@ -2993,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"); @@ -3001,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"); @@ -3035,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; } @@ -3044,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; } @@ -3071,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"); @@ -3079,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; } @@ -3088,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"); @@ -3096,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"); @@ -3142,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; } @@ -3151,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"); @@ -3159,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; } @@ -3168,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"); @@ -3183,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; } @@ -3192,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; } @@ -3212,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"); @@ -3222,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; } @@ -3241,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; } @@ -3261,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; } @@ -3281,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; } @@ -3301,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; } @@ -3321,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; } @@ -3341,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"); @@ -3349,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; } @@ -3358,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"); @@ -3366,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; } @@ -3375,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; } @@ -3390,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"); @@ -3398,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; } @@ -3407,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"); @@ -3415,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; } @@ -3446,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"); @@ -3466,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; } @@ -3475,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"); @@ -3502,7 +3618,7 @@ 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; } @@ -3511,19 +3627,19 @@ bool js_cocos2dx_Node_runAction(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Node_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 = 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_visit : Invalid Native Object"); do { if (argc == 0) { cobj->visit(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3532,22 +3648,22 @@ bool js_cocos2dx_Node_visit(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->visit(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -3557,25 +3673,25 @@ bool js_cocos2dx_Node_visit(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -3584,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"); @@ -3592,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; } @@ -3601,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"); @@ -3609,37 +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_getRotationQuat(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_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_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; } @@ -3648,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; } @@ -3668,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"); @@ -3683,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; } @@ -3692,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; } @@ -3719,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; } @@ -3734,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"); @@ -3742,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; } @@ -3751,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"); @@ -3759,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; } @@ -3768,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; } @@ -3790,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"); @@ -3798,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; } @@ -3807,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; @@ -3827,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; } @@ -3836,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; } @@ -3856,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; } @@ -3876,72 +4017,29 @@ 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) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - - JSObject *obj = NULL; - cocos2d::Node* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); - 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); - - JS_ReportError(cx, "js_cocos2dx_Node_setAdditionalTransform : wrong number of arguments"); - return false; -} 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 = 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_updatePhysicsBodyTransform : Invalid Native Object"); @@ -3950,13 +4048,13 @@ bool js_cocos2dx_Node_updatePhysicsBodyTransform(JSContext *cx, uint32_t argc, j unsigned int arg1; double arg2; double arg3; - ok &= jsval_to_matrix(cx, argv[0], &arg0); - ok &= jsval_to_uint32(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_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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3965,7 +4063,8 @@ bool js_cocos2dx_Node_updatePhysicsBodyTransform(JSContext *cx, uint32_t argc, j } 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"); @@ -3973,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; } @@ -3982,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"); @@ -3990,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; } @@ -3999,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"); @@ -4020,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); @@ -4037,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); @@ -4045,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"); @@ -4072,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; } @@ -4081,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; } @@ -4108,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"); @@ -4128,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); @@ -4138,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); @@ -4148,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"); @@ -4156,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; } @@ -4165,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"); @@ -4186,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); @@ -4203,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); @@ -4211,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"); @@ -4221,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; } @@ -4230,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"); @@ -4238,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; } @@ -4247,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; } @@ -4277,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; } @@ -4297,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; } @@ -4317,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"); @@ -4362,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; } @@ -4371,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; } @@ -4391,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); @@ -4417,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); @@ -4430,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"); @@ -4438,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; } @@ -4447,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; @@ -4467,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; } @@ -4476,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; } @@ -4496,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"); @@ -4504,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; } @@ -4513,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"); @@ -4521,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; } @@ -4530,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"); @@ -4538,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; } @@ -4547,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; } @@ -4604,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; } @@ -4624,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; } @@ -4639,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; @@ -4659,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; } @@ -4668,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"); @@ -4676,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; } @@ -4685,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; } @@ -4705,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"); @@ -4713,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; } @@ -4722,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; } @@ -4749,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"); @@ -4757,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; } @@ -4766,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); @@ -4787,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); @@ -4812,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; } @@ -4839,20 +4937,20 @@ 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]; @@ -4864,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; @@ -4883,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; } @@ -4892,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"); @@ -4900,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; } @@ -4909,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); @@ -4931,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); @@ -4941,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; } @@ -4961,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; } @@ -4981,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"); @@ -5021,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; } @@ -5030,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"); @@ -5038,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; } @@ -5069,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; } @@ -5089,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"); @@ -5097,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; } @@ -5150,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"); @@ -5171,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); @@ -5188,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); @@ -5198,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; @@ -5209,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"); @@ -5218,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); @@ -5232,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; } @@ -5250,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; @@ -5278,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[] = { @@ -5311,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), @@ -5327,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), @@ -5348,6 +5477,7 @@ 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), @@ -5355,6 +5485,7 @@ void js_register_cocos2dx_Node(JSContext *cx, JSObject *global) { 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("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), @@ -5368,24 +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), @@ -5396,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), @@ -5414,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), @@ -5434,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, @@ -5465,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); @@ -5479,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; } @@ -5498,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; @@ -5526,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[] = { @@ -5539,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, @@ -5570,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"); @@ -5578,7 +5712,7 @@ 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; } @@ -5587,25 +5721,25 @@ bool js_cocos2dx_Scene_initWithPhysics(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -5614,25 +5748,25 @@ 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; } @@ -5641,7 +5775,8 @@ bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_Scene_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::Scene* cobj = (cocos2d::Scene *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Scene_init : Invalid Native Object"); @@ -5649,7 +5784,7 @@ bool js_cocos2dx_Scene_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; } @@ -5658,7 +5793,8 @@ bool js_cocos2dx_Scene_init(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -5673,7 +5809,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; } @@ -5682,20 +5818,20 @@ 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; } @@ -5704,7 +5840,8 @@ bool js_cocos2dx_Scene_initWithSize(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -5719,7 +5856,7 @@ bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5728,11 +5865,11 @@ bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp) } 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; @@ -5744,7 +5881,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"); @@ -5753,6 +5890,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; @@ -5764,7 +5902,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"); @@ -5773,6 +5911,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; @@ -5784,7 +5923,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"); @@ -5793,7 +5932,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); @@ -5807,13 +5946,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; } @@ -5826,21 +5968,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; @@ -5854,8 +5996,8 @@ 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[] = { @@ -5879,7 +6021,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, @@ -5910,20 +6052,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; } @@ -5932,7 +6074,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"); @@ -5940,7 +6083,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; } @@ -5949,20 +6092,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; } @@ -5971,7 +6114,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"); @@ -5979,7 +6123,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; } @@ -5988,18 +6132,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; } @@ -6008,9 +6152,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"); @@ -6019,13 +6163,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; } @@ -6034,7 +6178,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"); @@ -6042,7 +6187,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; } @@ -6051,7 +6196,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"); @@ -6059,7 +6205,7 @@ 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; } @@ -6068,7 +6214,8 @@ bool js_cocos2dx_GLView_isOpenGLReady(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -6076,7 +6223,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; } @@ -6085,7 +6232,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"); @@ -6093,7 +6241,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; } @@ -6102,7 +6250,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"); @@ -6110,7 +6259,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; } @@ -6119,7 +6268,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"); @@ -6127,7 +6277,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; } @@ -6136,18 +6286,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; } @@ -6156,7 +6306,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"); @@ -6164,7 +6315,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; } @@ -6173,7 +6324,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"); @@ -6181,7 +6333,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; } @@ -6190,7 +6342,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"); @@ -6198,7 +6351,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; } @@ -6207,9 +6360,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"); @@ -6217,12 +6370,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; } @@ -6231,7 +6384,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"); @@ -6239,7 +6393,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; } @@ -6248,7 +6402,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"); @@ -6256,7 +6411,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; } @@ -6265,9 +6420,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"); @@ -6276,13 +6431,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; } @@ -6291,7 +6446,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"); @@ -6299,7 +6455,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; } @@ -6308,7 +6464,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"); @@ -6316,7 +6473,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; } @@ -6325,18 +6482,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; } @@ -6345,7 +6502,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"); @@ -6353,7 +6511,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; } @@ -6362,7 +6520,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"); @@ -6370,7 +6529,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; } @@ -6379,7 +6538,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"); @@ -6387,7 +6547,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; } @@ -6396,13 +6556,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; } @@ -6411,7 +6572,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; @@ -6419,7 +6580,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"); @@ -6428,11 +6589,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"); @@ -6445,7 +6607,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; @@ -6459,8 +6621,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[] = { @@ -6502,7 +6664,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, @@ -6533,13 +6695,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; } @@ -6548,25 +6711,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; } @@ -6575,18 +6738,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; } @@ -6595,7 +6758,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"); @@ -6603,7 +6767,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; } @@ -6612,7 +6776,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"); @@ -6620,7 +6785,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; } @@ -6629,7 +6794,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"); @@ -6637,7 +6803,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; } @@ -6646,13 +6812,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; } @@ -6661,25 +6828,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; } @@ -6688,18 +6855,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; } @@ -6708,13 +6875,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; } @@ -6723,20 +6891,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; } @@ -6745,7 +6913,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"); @@ -6760,7 +6929,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; } @@ -6769,7 +6938,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"); @@ -6777,7 +6947,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; } @@ -6786,13 +6956,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; } @@ -6801,7 +6972,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"); @@ -6816,7 +6988,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; } @@ -6825,7 +6997,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"); @@ -6833,7 +7006,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; } @@ -6842,7 +7015,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"); @@ -6850,7 +7024,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; } @@ -6859,13 +7033,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; } @@ -6874,18 +7049,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; } @@ -6894,7 +7069,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"); @@ -6902,7 +7078,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; } @@ -6911,7 +7087,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"); @@ -6919,7 +7096,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; } @@ -6928,13 +7105,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; } @@ -6943,20 +7121,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; } @@ -6965,18 +7143,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; } @@ -6985,13 +7163,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; } @@ -7000,7 +7179,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"); @@ -7008,7 +7188,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; } @@ -7017,25 +7197,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; } @@ -7044,20 +7224,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; } @@ -7066,13 +7246,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; } @@ -7081,7 +7262,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"); @@ -7096,7 +7278,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; } @@ -7105,7 +7287,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"); @@ -7120,7 +7303,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; } @@ -7129,13 +7312,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; } @@ -7144,13 +7328,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; } @@ -7159,18 +7344,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; } @@ -7179,13 +7364,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; } @@ -7194,7 +7380,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"); @@ -7202,7 +7389,7 @@ 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; } @@ -7211,18 +7398,18 @@ bool js_cocos2dx_Director_isNextDeltaTimeZero(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_Director_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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7231,25 +7418,25 @@ bool js_cocos2dx_Director_setClearColor(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -7258,20 +7445,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; } @@ -7280,13 +7467,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; } @@ -7295,7 +7483,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"); @@ -7303,7 +7492,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; } @@ -7312,25 +7501,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; } @@ -7339,25 +7528,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; } @@ -7366,13 +7555,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; } @@ -7381,13 +7571,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; } @@ -7396,13 +7587,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; } @@ -7411,18 +7603,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; } @@ -7431,7 +7623,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"); @@ -7439,7 +7632,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; } @@ -7448,18 +7641,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; } @@ -7468,20 +7661,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; } @@ -7490,7 +7683,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"); @@ -7498,7 +7692,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; } @@ -7507,18 +7701,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; } @@ -7527,18 +7721,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; } @@ -7547,7 +7741,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"); @@ -7555,7 +7750,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; } @@ -7564,7 +7759,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"); @@ -7579,7 +7775,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; } @@ -7588,25 +7784,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; } @@ -7615,7 +7811,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"); @@ -7623,7 +7820,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; } @@ -7632,7 +7829,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"); @@ -7640,7 +7838,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; } @@ -7649,18 +7847,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; } @@ -7669,7 +7867,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"); @@ -7684,7 +7883,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; } @@ -7693,25 +7892,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; } @@ -7720,18 +7919,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; } @@ -7740,7 +7939,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"); @@ -7755,7 +7955,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; } @@ -7764,6 +7964,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; @@ -7775,7 +7976,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"); @@ -7788,7 +7989,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; @@ -7802,8 +8003,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[] = { @@ -7880,7 +8081,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, @@ -7911,18 +8112,18 @@ 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; } @@ -7931,22 +8132,22 @@ bool js_cocos2dx_Scheduler_setTimeScale(JSContext *cx, uint32_t argc, jsval *vp) } 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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -7961,7 +8162,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; } @@ -7970,7 +8171,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"); @@ -7978,7 +8180,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; } @@ -7987,7 +8189,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); @@ -8001,13 +8203,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; } @@ -8017,7 +8222,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; @@ -8031,8 +8236,8 @@ 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[] = { @@ -8046,7 +8251,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, @@ -8077,20 +8282,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; } @@ -8099,20 +8304,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; } @@ -8121,20 +8326,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; } @@ -8143,20 +8348,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; } @@ -8165,9 +8370,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"); @@ -8175,14 +8380,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; } @@ -8191,18 +8396,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; } @@ -8211,7 +8416,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"); @@ -8219,7 +8425,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; } @@ -8228,20 +8434,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; } @@ -8250,7 +8456,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"); @@ -8258,7 +8465,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; } @@ -8267,22 +8474,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; } @@ -8291,20 +8498,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; } @@ -8313,22 +8520,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; } @@ -8337,20 +8544,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; } @@ -8359,18 +8566,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; } @@ -8379,20 +8586,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; } @@ -8401,18 +8608,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; } @@ -8421,28 +8628,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; } @@ -8451,28 +8658,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; } @@ -8481,20 +8688,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; } @@ -8503,13 +8710,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; } @@ -8518,22 +8726,22 @@ 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; } @@ -8542,18 +8750,18 @@ bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc } bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setWritablePath : 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_setWritablePath : Error processing arguments"); cobj->setWritablePath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8562,18 +8770,18 @@ bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval * } 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; } @@ -8582,20 +8790,20 @@ 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; } @@ -8604,18 +8812,18 @@ bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_FileUtils_setDefaultResourceRootPath(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setDefaultResourceRootPath : 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_setDefaultResourceRootPath : Error processing arguments"); cobj->setDefaultResourceRootPath(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8624,7 +8832,8 @@ bool js_cocos2dx_FileUtils_setDefaultResourceRootPath(JSContext *cx, uint32_t ar } 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"); @@ -8632,7 +8841,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; } @@ -8641,20 +8850,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; } @@ -8663,7 +8872,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"); @@ -8671,7 +8881,7 @@ 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; } @@ -8680,21 +8890,21 @@ bool js_cocos2dx_FileUtils_getWritablePath(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_FileUtils_setDelegate(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::FileUtils* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_FileUtils_setDelegate : wrong number of arguments"); @@ -8703,6 +8913,7 @@ bool js_cocos2dx_FileUtils_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) 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; @@ -8714,7 +8925,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"); @@ -8727,7 +8938,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; @@ -8741,8 +8952,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[] = { @@ -8785,7 +8996,7 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JSObject *global) { jsb_cocos2d_FileUtils_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_FileUtils_class, empty_constructor, 0, properties, @@ -8816,18 +9027,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; } @@ -8836,7 +9047,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"); @@ -8844,7 +9056,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; } @@ -8853,7 +9065,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"); @@ -8868,7 +9081,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; } @@ -8877,7 +9090,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"); @@ -8885,7 +9099,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; } @@ -8898,7 +9112,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; @@ -8912,8 +9126,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[] = { @@ -8928,7 +9142,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, @@ -8959,18 +9173,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; } @@ -8979,13 +9193,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; } @@ -8994,9 +9209,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"); @@ -9004,24 +9219,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; } @@ -9030,20 +9245,20 @@ 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]; @@ -9055,8 +9270,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); } @@ -9080,7 +9295,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; } @@ -9089,9 +9304,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"); @@ -9099,17 +9314,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; } @@ -9118,12 +9333,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"); @@ -9131,16 +9346,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); @@ -9149,18 +9364,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); @@ -9168,10 +9383,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); @@ -9181,42 +9396,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; } @@ -9225,9 +9440,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"); @@ -9235,17 +9450,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; } @@ -9254,25 +9469,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; } @@ -9281,42 +9496,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; } @@ -9325,18 +9540,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; } @@ -9345,25 +9560,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; } @@ -9372,7 +9587,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"); @@ -9380,7 +9596,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; } @@ -9389,7 +9605,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); @@ -9403,13 +9619,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; } @@ -9419,7 +9638,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; @@ -9433,8 +9652,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[] = { @@ -9458,7 +9677,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, @@ -9489,7 +9708,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"); @@ -9497,7 +9717,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; } @@ -9506,18 +9726,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; } @@ -9526,7 +9746,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"); @@ -9534,7 +9755,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; } @@ -9543,7 +9764,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); @@ -9557,13 +9778,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; } @@ -9574,7 +9798,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; @@ -9588,8 +9812,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[] = { @@ -9603,7 +9827,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, @@ -9634,7 +9858,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"); @@ -9642,7 +9867,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; } @@ -9651,7 +9876,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); @@ -9665,13 +9890,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; } @@ -9682,7 +9910,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; @@ -9696,8 +9924,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[] = { @@ -9709,7 +9937,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, @@ -9740,7 +9968,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"); @@ -9748,7 +9977,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; } @@ -9757,7 +9986,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); @@ -9771,13 +10000,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; } @@ -9788,7 +10020,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; @@ -9802,8 +10034,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[] = { @@ -9815,7 +10047,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, @@ -9846,7 +10078,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"); @@ -9854,7 +10087,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; } @@ -9863,7 +10096,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"); @@ -9871,7 +10105,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; } @@ -9880,18 +10114,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; } @@ -9900,20 +10134,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; } @@ -9922,7 +10156,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"); @@ -9930,7 +10165,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; } @@ -9939,7 +10174,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"); @@ -9947,7 +10183,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; } @@ -9956,7 +10192,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"); @@ -9964,7 +10201,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; } @@ -9973,7 +10210,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"); @@ -9981,7 +10219,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; } @@ -9990,7 +10228,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"); @@ -9998,7 +10237,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; } @@ -10007,7 +10246,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"); @@ -10015,7 +10255,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; } @@ -10024,7 +10264,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"); @@ -10032,7 +10273,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; } @@ -10041,20 +10282,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; } @@ -10063,7 +10304,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"); @@ -10071,7 +10313,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; } @@ -10080,7 +10322,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"); @@ -10088,7 +10331,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; } @@ -10097,7 +10340,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"); @@ -10105,7 +10349,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; } @@ -10114,10 +10358,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); @@ -10131,13 +10375,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; } @@ -10148,7 +10395,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; @@ -10162,8 +10409,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[] = { @@ -10189,7 +10436,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, @@ -10220,7 +10467,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"); @@ -10228,7 +10476,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; } @@ -10237,7 +10485,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); @@ -10251,13 +10499,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; } @@ -10268,7 +10519,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; @@ -10282,8 +10533,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[] = { @@ -10295,7 +10546,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, @@ -10326,10 +10577,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); @@ -10343,13 +10594,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; } @@ -10360,7 +10614,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; @@ -10374,8 +10628,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[] = { @@ -10386,7 +10640,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, @@ -10417,18 +10671,18 @@ 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]; @@ -10441,8 +10695,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); } @@ -10459,7 +10713,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; } @@ -10468,14 +10722,14 @@ 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]; @@ -10488,8 +10742,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); } @@ -10513,7 +10767,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"); @@ -10522,7 +10776,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); @@ -10536,13 +10790,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; } @@ -10553,7 +10810,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; @@ -10567,8 +10824,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[] = { @@ -10583,7 +10840,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, @@ -10614,7 +10871,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"); @@ -10622,7 +10880,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; } @@ -10631,10 +10889,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); @@ -10648,13 +10906,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; } @@ -10665,7 +10926,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; @@ -10679,8 +10940,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[] = { @@ -10692,7 +10953,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, @@ -10723,16 +10984,16 @@ 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]; @@ -10744,8 +11005,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); } @@ -10769,7 +11030,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"); @@ -10778,7 +11039,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); @@ -10792,13 +11053,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; } @@ -10809,7 +11073,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; @@ -10823,8 +11087,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[] = { @@ -10838,7 +11102,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, @@ -10869,22 +11133,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"); @@ -10902,13 +11166,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; } @@ -10919,7 +11186,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; @@ -10933,8 +11200,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[] = { @@ -10945,7 +11212,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, @@ -10976,7 +11243,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"); @@ -10984,7 +11252,7 @@ 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; } @@ -10993,7 +11261,7 @@ bool js_cocos2dx_EventListenerFocus_init(JSContext *cx, uint32_t argc, jsval *vp } 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); @@ -11007,13 +11275,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; } @@ -11024,7 +11295,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; @@ -11038,8 +11309,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[] = { @@ -11051,7 +11322,7 @@ void js_register_cocos2dx_EventListenerFocus(JSContext *cx, JSObject *global) { 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, @@ -11082,25 +11353,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; } @@ -11109,25 +11380,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; } @@ -11136,7 +11407,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"); @@ -11151,7 +11423,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; } @@ -11160,7 +11432,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"); @@ -11175,7 +11448,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; } @@ -11184,13 +11457,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; } @@ -11199,18 +11473,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; } @@ -11219,7 +11493,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"); @@ -11234,7 +11509,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; } @@ -11243,18 +11518,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; } @@ -11263,18 +11538,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; } @@ -11283,7 +11558,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"); @@ -11291,7 +11567,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; } @@ -11300,25 +11576,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; } @@ -11327,7 +11603,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"); @@ -11335,7 +11612,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; } @@ -11344,7 +11621,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"); @@ -11359,7 +11637,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; } @@ -11372,7 +11650,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; @@ -11386,8 +11664,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[] = { @@ -11411,7 +11689,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, @@ -11442,18 +11720,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; } @@ -11462,7 +11740,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"); @@ -11470,7 +11749,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; } @@ -11484,7 +11763,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; @@ -11498,8 +11777,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[] = { @@ -11512,7 +11791,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, @@ -11543,25 +11822,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; } @@ -11570,7 +11849,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"); @@ -11578,7 +11858,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; } @@ -11587,18 +11867,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; } @@ -11607,9 +11887,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"); @@ -11617,19 +11897,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; } @@ -11638,7 +11918,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"); @@ -11653,7 +11934,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; } @@ -11662,20 +11943,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; @@ -11687,7 +11968,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"); @@ -11696,7 +11977,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); @@ -11710,13 +11991,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; } @@ -11727,7 +12011,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; @@ -11741,8 +12025,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[] = { @@ -11761,7 +12045,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, @@ -11792,18 +12076,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; } @@ -11812,18 +12096,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"); @@ -11832,26 +12116,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; } @@ -11860,7 +12144,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"); @@ -11868,7 +12153,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; } @@ -11877,14 +12162,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"); @@ -11900,21 +12185,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; @@ -11926,7 +12211,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"); @@ -11935,7 +12220,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); @@ -11949,13 +12234,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; } @@ -11966,7 +12254,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; @@ -11980,8 +12268,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[] = { @@ -11998,7 +12286,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, @@ -12029,7 +12317,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"); @@ -12044,7 +12333,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; } @@ -12053,18 +12342,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; } @@ -12073,25 +12362,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; } @@ -12100,7 +12389,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"); @@ -12108,7 +12398,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; } @@ -12117,18 +12407,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; } @@ -12137,7 +12427,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"); @@ -12152,7 +12443,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; } @@ -12161,7 +12452,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"); @@ -12169,7 +12461,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; } @@ -12178,18 +12470,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; } @@ -12198,7 +12490,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"); @@ -12206,7 +12499,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; } @@ -12215,18 +12508,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; } @@ -12235,7 +12528,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"); @@ -12243,7 +12537,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; } @@ -12252,18 +12546,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; } @@ -12272,18 +12566,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; } @@ -12292,12 +12586,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"); @@ -12305,29 +12599,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); @@ -12336,21 +12630,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); @@ -12360,7 +12654,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"); @@ -12368,7 +12663,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; } @@ -12377,35 +12672,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); @@ -12413,15 +12708,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); @@ -12431,18 +12726,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; } @@ -12451,7 +12746,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"); @@ -12459,7 +12755,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; } @@ -12468,7 +12764,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"); @@ -12476,7 +12773,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; } @@ -12485,25 +12782,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; @@ -12515,7 +12812,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); @@ -12523,10 +12820,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; @@ -12538,7 +12835,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); @@ -12547,32 +12844,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; @@ -12584,7 +12881,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); @@ -12593,16 +12890,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; @@ -12614,7 +12911,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); @@ -12623,7 +12920,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); @@ -12637,13 +12934,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; } @@ -12655,21 +12955,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; @@ -12683,8 +12983,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[] = { @@ -12719,7 +13019,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, @@ -12750,25 +13050,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; } @@ -12777,12 +13077,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"); @@ -12791,7 +13091,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); @@ -12801,7 +13101,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); @@ -12811,18 +13111,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; } @@ -12831,7 +13131,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"); @@ -12846,7 +13147,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; } @@ -12855,7 +13156,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"); @@ -12870,7 +13172,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; } @@ -12879,7 +13181,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"); @@ -12887,7 +13190,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; } @@ -12896,18 +13199,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; } @@ -12916,9 +13219,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"); @@ -12927,20 +13230,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; } @@ -12949,22 +13252,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; @@ -12976,7 +13279,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"); @@ -12985,7 +13288,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); @@ -12999,13 +13302,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; } @@ -13015,7 +13321,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; @@ -13029,8 +13335,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[] = { @@ -13052,7 +13358,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, @@ -13083,7 +13389,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"); @@ -13091,7 +13398,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; } @@ -13100,25 +13407,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; } @@ -13127,18 +13434,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; } @@ -13147,7 +13454,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"); @@ -13162,7 +13470,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; } @@ -13171,7 +13479,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"); @@ -13179,7 +13488,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; } @@ -13188,9 +13497,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"); @@ -13198,14 +13507,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; } @@ -13214,7 +13523,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"); @@ -13222,7 +13532,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; } @@ -13231,18 +13541,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; } @@ -13251,7 +13561,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"); @@ -13259,7 +13570,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; } @@ -13268,18 +13579,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; } @@ -13288,18 +13599,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; } @@ -13308,18 +13619,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; } @@ -13328,7 +13639,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"); @@ -13336,7 +13648,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; } @@ -13345,7 +13657,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"); @@ -13353,7 +13666,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; } @@ -13362,46 +13675,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; } @@ -13410,7 +13723,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"); @@ -13418,7 +13732,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; } @@ -13427,9 +13741,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"); @@ -13437,17 +13751,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; } @@ -13456,16 +13770,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; @@ -13477,20 +13791,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; @@ -13502,7 +13816,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); @@ -13519,7 +13833,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); @@ -13528,11 +13842,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; @@ -13544,14 +13858,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; @@ -13563,16 +13877,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; @@ -13584,7 +13898,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"); @@ -13593,7 +13907,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); @@ -13607,13 +13921,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; } @@ -13623,7 +13940,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; @@ -13637,8 +13954,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[] = { @@ -13670,7 +13987,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, @@ -13701,7 +14018,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"); @@ -13709,7 +14027,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; } @@ -13718,20 +14036,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; } @@ -13740,18 +14058,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; } @@ -13760,7 +14078,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"); @@ -13768,7 +14087,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; } @@ -13782,7 +14101,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; @@ -13796,8 +14115,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[] = { @@ -13812,7 +14131,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, @@ -13843,9 +14162,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"); @@ -13853,17 +14172,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"); @@ -13872,7 +14191,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; } @@ -13881,7 +14200,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); @@ -13895,13 +14214,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; } @@ -13912,7 +14234,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; @@ -13926,8 +14248,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[] = { @@ -13939,7 +14261,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, @@ -13970,25 +14292,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; } @@ -13997,9 +14319,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"); @@ -14007,19 +14329,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; } @@ -14028,7 +14350,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"); @@ -14043,7 +14366,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; } @@ -14052,20 +14375,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; @@ -14077,7 +14400,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"); @@ -14086,7 +14409,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); @@ -14100,13 +14423,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; } @@ -14117,7 +14443,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; @@ -14131,8 +14457,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[] = { @@ -14149,7 +14475,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, @@ -14180,25 +14506,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; } @@ -14207,18 +14533,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"); @@ -14227,7 +14553,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; } @@ -14236,7 +14562,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"); @@ -14251,7 +14578,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; } @@ -14260,14 +14587,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"); @@ -14283,7 +14610,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"); @@ -14292,7 +14619,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); @@ -14306,13 +14633,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; } @@ -14323,7 +14653,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; @@ -14337,8 +14667,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[] = { @@ -14355,7 +14685,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, @@ -14386,9 +14716,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"); @@ -14396,17 +14726,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"); @@ -14415,7 +14745,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; } @@ -14424,7 +14754,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); @@ -14438,13 +14768,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; } @@ -14455,7 +14788,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; @@ -14469,8 +14802,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[] = { @@ -14482,7 +14815,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, @@ -14513,27 +14846,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); @@ -14541,18 +14874,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); @@ -14562,16 +14895,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; @@ -14583,7 +14916,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); @@ -14591,13 +14924,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; @@ -14609,7 +14942,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); @@ -14617,10 +14950,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; @@ -14632,7 +14965,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); @@ -14641,7 +14974,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); @@ -14655,13 +14988,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; } @@ -14672,7 +15008,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; @@ -14686,8 +15022,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[] = { @@ -14702,7 +15038,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, @@ -14733,30 +15069,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); @@ -14764,15 +15100,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); @@ -14780,15 +15116,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); @@ -14798,19 +15134,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; @@ -14822,7 +15158,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); @@ -14830,10 +15166,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; @@ -14845,7 +15181,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); @@ -14853,10 +15189,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; @@ -14868,7 +15204,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); @@ -14877,7 +15213,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); @@ -14891,13 +15227,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; } @@ -14908,7 +15247,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; @@ -14922,8 +15261,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[] = { @@ -14938,7 +15277,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, @@ -14969,27 +15308,27 @@ 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 = NULL; + JS::RootedObject obj(cx); cocos2d::MoveBy* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::MoveBy *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MoveBy_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); @@ -14997,15 +15336,15 @@ bool js_cocos2dx_MoveBy_initWithDuration(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::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -15015,16 +15354,16 @@ bool js_cocos2dx_MoveBy_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } 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; 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::MoveBy* ret = cocos2d::MoveBy::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -15036,7 +15375,7 @@ bool js_cocos2dx_MoveBy_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); @@ -15044,10 +15383,10 @@ bool js_cocos2dx_MoveBy_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::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::MoveBy* ret = cocos2d::MoveBy::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -15059,7 +15398,7 @@ bool js_cocos2dx_MoveBy_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); @@ -15068,7 +15407,7 @@ bool js_cocos2dx_MoveBy_create(JSContext *cx, uint32_t argc, jsval *vp) } 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); @@ -15082,13 +15421,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; } @@ -15099,7 +15441,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; @@ -15113,8 +15455,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[] = { @@ -15129,7 +15471,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, @@ -15160,27 +15502,27 @@ 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 = NULL; + JS::RootedObject obj(cx); cocos2d::MoveTo* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::MoveTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_MoveTo_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); @@ -15188,15 +15530,15 @@ bool js_cocos2dx_MoveTo_initWithDuration(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::Vec2 arg1; - ok &= jsval_to_vector2(cx, argv[1], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -15206,16 +15548,16 @@ bool js_cocos2dx_MoveTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } 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; 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::MoveTo* ret = cocos2d::MoveTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -15227,7 +15569,7 @@ bool js_cocos2dx_MoveTo_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); @@ -15235,10 +15577,10 @@ bool js_cocos2dx_MoveTo_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::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::MoveTo* ret = cocos2d::MoveTo::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -15250,7 +15592,7 @@ bool js_cocos2dx_MoveTo_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); @@ -15259,7 +15601,7 @@ bool js_cocos2dx_MoveTo_create(JSContext *cx, uint32_t argc, jsval *vp) } 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); @@ -15273,13 +15615,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; } @@ -15290,7 +15635,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; @@ -15304,8 +15649,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[] = { @@ -15320,7 +15665,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, @@ -15351,9 +15696,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"); @@ -15361,14 +15706,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; } @@ -15377,15 +15722,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; @@ -15397,7 +15742,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"); @@ -15406,7 +15751,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); @@ -15420,13 +15765,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; } @@ -15437,7 +15785,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; @@ -15451,8 +15799,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[] = { @@ -15467,7 +15815,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, @@ -15498,9 +15846,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"); @@ -15508,14 +15856,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; } @@ -15524,15 +15872,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; @@ -15544,7 +15892,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"); @@ -15553,7 +15901,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); @@ -15567,13 +15915,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; } @@ -15584,7 +15935,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; @@ -15598,8 +15949,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[] = { @@ -15614,7 +15965,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, @@ -15645,9 +15996,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"); @@ -15656,15 +16007,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; } @@ -15673,17 +16024,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; @@ -15695,7 +16046,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"); @@ -15704,7 +16055,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); @@ -15718,13 +16069,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; } @@ -15735,7 +16089,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; @@ -15749,8 +16103,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[] = { @@ -15765,7 +16119,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, @@ -15796,9 +16150,9 @@ JSObject *jsb_cocos2d_JumpTo_prototype; bool js_cocos2dx_JumpTo_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::JumpTo* cobj = (cocos2d::JumpTo *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_JumpTo_initWithDuration : Invalid Native Object"); @@ -15807,15 +16161,15 @@ bool js_cocos2dx_JumpTo_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_JumpTo_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; } @@ -15824,17 +16178,17 @@ bool js_cocos2dx_JumpTo_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp } 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; @@ -15846,7 +16200,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"); @@ -15855,7 +16209,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); @@ -15869,13 +16223,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; } @@ -15886,7 +16243,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; @@ -15900,8 +16257,8 @@ 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[] = { @@ -15916,7 +16273,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, @@ -15947,7 +16304,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); @@ -15961,13 +16318,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; } @@ -15978,7 +16338,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; @@ -15992,8 +16352,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[] = { @@ -16004,7 +16364,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, @@ -16035,7 +16395,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); @@ -16049,13 +16409,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; } @@ -16066,7 +16429,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; @@ -16080,8 +16443,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[] = { @@ -16092,7 +16455,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, @@ -16123,30 +16486,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); @@ -16154,15 +16517,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); @@ -16170,21 +16533,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); @@ -16194,19 +16557,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; @@ -16218,7 +16581,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); @@ -16226,10 +16589,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; @@ -16241,7 +16604,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); @@ -16249,16 +16612,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; @@ -16270,7 +16633,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); @@ -16279,7 +16642,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); @@ -16293,13 +16656,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; } @@ -16310,7 +16676,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; @@ -16324,8 +16690,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[] = { @@ -16340,7 +16706,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, @@ -16371,19 +16737,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; @@ -16395,7 +16761,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); @@ -16403,10 +16769,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; @@ -16418,7 +16784,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); @@ -16426,16 +16792,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; @@ -16447,7 +16813,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); @@ -16456,7 +16822,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); @@ -16470,13 +16836,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; } @@ -16487,7 +16856,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; @@ -16501,8 +16870,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[] = { @@ -16516,7 +16885,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, @@ -16547,22 +16916,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; } @@ -16571,13 +16940,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; @@ -16589,7 +16958,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"); @@ -16598,7 +16967,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); @@ -16612,13 +16981,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; } @@ -16629,7 +17001,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; @@ -16643,8 +17015,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[] = { @@ -16659,7 +17031,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, @@ -16690,22 +17062,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; } @@ -16714,13 +17086,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; @@ -16732,7 +17104,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"); @@ -16741,7 +17113,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); @@ -16755,13 +17127,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; } @@ -16772,7 +17147,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; @@ -16786,8 +17161,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[] = { @@ -16802,7 +17177,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, @@ -16833,25 +17208,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; } @@ -16860,11 +17235,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; @@ -16876,7 +17251,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"); @@ -16885,7 +17260,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); @@ -16899,13 +17274,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; } @@ -16916,7 +17294,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; @@ -16930,8 +17308,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[] = { @@ -16946,7 +17324,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, @@ -16977,25 +17355,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; } @@ -17004,11 +17382,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; @@ -17020,7 +17398,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"); @@ -17029,7 +17407,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); @@ -17043,13 +17421,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; } @@ -17060,7 +17441,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; @@ -17074,8 +17455,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[] = { @@ -17090,7 +17471,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, @@ -17121,9 +17502,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"); @@ -17132,15 +17513,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; } @@ -17149,16 +17530,16 @@ 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; 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::Color3B arg1; - ok &= jsval_to_cccolor3b(cx, argv[1], &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; @@ -17170,7 +17551,7 @@ bool js_cocos2dx_TintTo_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); @@ -17178,16 +17559,16 @@ bool js_cocos2dx_TintTo_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; } uint16_t arg1; - ok &= jsval_to_uint16(cx, argv[1], &arg1); + ok &= jsval_to_uint16(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } uint16_t arg2; - ok &= jsval_to_uint16(cx, argv[2], &arg2); + ok &= jsval_to_uint16(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } uint16_t arg3; - ok &= jsval_to_uint16(cx, argv[3], &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; @@ -17199,7 +17580,7 @@ bool js_cocos2dx_TintTo_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); @@ -17208,7 +17589,7 @@ bool js_cocos2dx_TintTo_create(JSContext *cx, uint32_t argc, jsval *vp) } 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); @@ -17222,13 +17603,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; } @@ -17239,7 +17623,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; @@ -17253,8 +17637,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[] = { @@ -17269,7 +17653,7 @@ void js_register_cocos2dx_TintTo(JSContext *cx, JSObject *global) { 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, @@ -17300,9 +17684,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"); @@ -17311,15 +17695,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; } @@ -17328,17 +17712,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; @@ -17350,7 +17734,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"); @@ -17359,7 +17743,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); @@ -17373,13 +17757,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; } @@ -17390,7 +17777,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; @@ -17404,8 +17791,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[] = { @@ -17420,7 +17807,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, @@ -17451,11 +17838,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; @@ -17467,7 +17854,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"); @@ -17476,7 +17863,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); @@ -17490,13 +17877,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; } @@ -17507,7 +17897,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; @@ -17521,8 +17911,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[] = { @@ -17536,7 +17926,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, @@ -17567,18 +17957,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"); @@ -17587,7 +17977,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; } @@ -17596,14 +17986,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"); @@ -17619,7 +18009,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"); @@ -17628,7 +18018,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); @@ -17642,13 +18032,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; } @@ -17659,7 +18052,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; @@ -17673,8 +18066,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[] = { @@ -17689,7 +18082,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, @@ -17720,12 +18113,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"); @@ -17741,7 +18134,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); @@ -17758,7 +18151,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); @@ -17768,18 +18161,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"); @@ -17788,7 +18181,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; } @@ -17797,25 +18190,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; } @@ -17824,14 +18217,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"); @@ -17847,7 +18240,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"); @@ -17856,7 +18249,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); @@ -17870,13 +18263,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; } @@ -17887,7 +18283,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; @@ -17901,8 +18297,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[] = { @@ -17919,7 +18315,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, @@ -17950,12 +18346,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"); @@ -17971,7 +18367,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); @@ -17988,7 +18384,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); @@ -17998,9 +18394,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"); @@ -18008,17 +18404,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"); @@ -18027,7 +18423,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; } @@ -18036,25 +18432,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; } @@ -18063,23 +18459,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"); @@ -18095,7 +18491,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"); @@ -18104,7 +18500,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); @@ -18118,13 +18514,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; } @@ -18137,21 +18536,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; @@ -18165,8 +18564,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[] = { @@ -18184,7 +18583,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, @@ -18215,28 +18614,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); @@ -18244,10 +18643,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); @@ -18257,7 +18656,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"); @@ -18265,7 +18665,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; } @@ -18274,18 +18674,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; } @@ -18294,7 +18694,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"); @@ -18302,7 +18703,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; } @@ -18311,18 +18712,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; } @@ -18331,7 +18732,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"); @@ -18339,7 +18741,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; } @@ -18348,7 +18750,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); @@ -18362,13 +18764,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; } @@ -18381,21 +18786,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; @@ -18409,8 +18814,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[] = { @@ -18428,7 +18833,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, @@ -18459,9 +18864,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"); @@ -18477,7 +18882,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; } @@ -18486,9 +18891,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"); @@ -18500,18 +18905,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; } @@ -18520,7 +18925,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; @@ -18530,13 +18935,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; @@ -18548,7 +18953,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"); @@ -18557,7 +18962,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); @@ -18571,13 +18976,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; } @@ -18588,7 +18996,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; @@ -18602,8 +19010,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[] = { @@ -18619,7 +19027,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, @@ -18650,20 +19058,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"); @@ -18679,7 +19087,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; } @@ -18688,27 +19096,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; } @@ -18717,13 +19125,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; } @@ -18732,9 +19141,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"); @@ -18743,25 +19152,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; } @@ -18770,25 +19179,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; } @@ -18797,18 +19206,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; } @@ -18817,25 +19226,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; } @@ -18844,18 +19253,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"); @@ -18864,7 +19273,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; } @@ -18873,25 +19282,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; } @@ -18900,18 +19309,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; } @@ -18920,25 +19329,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; } @@ -18947,27 +19356,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; } @@ -18976,7 +19385,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"); @@ -18984,7 +19394,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; } @@ -18993,7 +19403,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); @@ -19007,13 +19417,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; } @@ -19025,21 +19438,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; @@ -19053,8 +19466,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[] = { @@ -19079,7 +19492,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, @@ -19110,18 +19523,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"); @@ -19130,7 +19543,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; } @@ -19139,7 +19552,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"); @@ -19154,7 +19568,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; } @@ -19168,7 +19582,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; @@ -19182,8 +19596,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[] = { @@ -19196,7 +19610,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, @@ -19227,18 +19641,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; } @@ -19247,9 +19661,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"); @@ -19257,19 +19671,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; } @@ -19278,7 +19692,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"); @@ -19286,7 +19701,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; } @@ -19300,7 +19715,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; @@ -19314,8 +19729,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[] = { @@ -19329,7 +19744,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, @@ -19360,20 +19775,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; @@ -19385,7 +19800,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"); @@ -19394,7 +19809,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); @@ -19408,13 +19823,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; } @@ -19425,7 +19843,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; @@ -19439,8 +19857,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[] = { @@ -19454,7 +19872,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, @@ -19485,20 +19903,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; @@ -19510,7 +19928,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"); @@ -19519,7 +19937,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); @@ -19533,13 +19951,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; } @@ -19550,7 +19971,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; @@ -19564,8 +19985,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[] = { @@ -19579,7 +20000,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, @@ -19610,20 +20031,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; @@ -19635,7 +20056,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"); @@ -19644,7 +20065,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); @@ -19658,13 +20079,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; } @@ -19675,7 +20099,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; @@ -19689,8 +20113,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[] = { @@ -19704,7 +20128,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, @@ -19735,14 +20159,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"); @@ -19758,7 +20182,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"); @@ -19767,7 +20191,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); @@ -19781,13 +20205,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; } @@ -19798,7 +20225,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; @@ -19812,8 +20239,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[] = { @@ -19827,7 +20254,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, @@ -19858,14 +20285,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"); @@ -19881,7 +20308,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"); @@ -19890,7 +20317,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); @@ -19904,13 +20331,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; } @@ -19921,7 +20351,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; @@ -19935,8 +20365,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[] = { @@ -19950,7 +20380,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, @@ -19981,14 +20411,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"); @@ -20004,7 +20434,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"); @@ -20013,7 +20443,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); @@ -20027,13 +20457,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; } @@ -20044,7 +20477,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; @@ -20058,8 +20491,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[] = { @@ -20073,7 +20506,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, @@ -20104,14 +20537,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"); @@ -20127,7 +20560,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"); @@ -20136,7 +20569,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); @@ -20150,13 +20583,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; } @@ -20167,7 +20603,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; @@ -20181,8 +20617,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[] = { @@ -20196,7 +20632,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, @@ -20227,14 +20663,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"); @@ -20250,7 +20686,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"); @@ -20259,7 +20695,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); @@ -20273,13 +20709,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; } @@ -20290,7 +20729,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; @@ -20304,8 +20743,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[] = { @@ -20319,7 +20758,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, @@ -20350,14 +20789,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"); @@ -20373,7 +20812,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"); @@ -20382,7 +20821,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); @@ -20396,13 +20835,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; } @@ -20413,7 +20855,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; @@ -20427,8 +20869,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[] = { @@ -20442,7 +20884,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, @@ -20473,18 +20915,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; } @@ -20493,18 +20935,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"); @@ -20513,26 +20955,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; } @@ -20541,7 +20983,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"); @@ -20549,7 +20992,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; } @@ -20563,7 +21006,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; @@ -20577,8 +21020,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[] = { @@ -20592,7 +21035,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, @@ -20623,16 +21066,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"); @@ -20648,7 +21091,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); @@ -20657,16 +21100,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; @@ -20678,7 +21121,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); @@ -20687,7 +21130,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); @@ -20701,13 +21144,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; } @@ -20718,7 +21164,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; @@ -20732,8 +21178,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[] = { @@ -20747,7 +21193,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, @@ -20778,16 +21224,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"); @@ -20803,7 +21249,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); @@ -20812,16 +21258,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; @@ -20833,7 +21279,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); @@ -20842,7 +21288,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); @@ -20856,13 +21302,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; } @@ -20873,7 +21322,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; @@ -20887,8 +21336,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[] = { @@ -20902,7 +21351,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, @@ -20933,16 +21382,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"); @@ -20958,7 +21407,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); @@ -20967,16 +21416,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; @@ -20988,7 +21437,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); @@ -20997,7 +21446,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); @@ -21011,13 +21460,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; } @@ -21028,7 +21480,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; @@ -21042,8 +21494,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[] = { @@ -21057,7 +21509,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, @@ -21093,7 +21545,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; @@ -21107,8 +21559,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[] = { @@ -21119,7 +21571,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, @@ -21150,14 +21602,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"); @@ -21173,7 +21625,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"); @@ -21182,7 +21634,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); @@ -21196,13 +21648,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; } @@ -21213,7 +21668,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; @@ -21227,8 +21682,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[] = { @@ -21242,7 +21697,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, @@ -21273,14 +21728,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"); @@ -21296,7 +21751,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"); @@ -21305,7 +21760,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); @@ -21319,13 +21774,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; } @@ -21336,7 +21794,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; @@ -21350,8 +21808,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[] = { @@ -21365,7 +21823,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, @@ -21396,14 +21854,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"); @@ -21419,7 +21877,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"); @@ -21428,7 +21886,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); @@ -21442,13 +21900,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; } @@ -21459,7 +21920,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; @@ -21473,8 +21934,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[] = { @@ -21488,7 +21949,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, @@ -21519,14 +21980,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"); @@ -21542,7 +22003,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"); @@ -21551,7 +22012,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); @@ -21565,13 +22026,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; } @@ -21582,7 +22046,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; @@ -21596,8 +22060,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[] = { @@ -21611,7 +22075,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, @@ -21642,14 +22106,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"); @@ -21665,7 +22129,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"); @@ -21674,7 +22138,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); @@ -21688,13 +22152,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; } @@ -21705,7 +22172,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; @@ -21719,8 +22186,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[] = { @@ -21734,7 +22201,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, @@ -21765,14 +22232,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"); @@ -21788,7 +22255,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"); @@ -21797,7 +22264,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); @@ -21811,13 +22278,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; } @@ -21828,7 +22298,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; @@ -21842,8 +22312,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[] = { @@ -21857,7 +22327,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, @@ -21888,9 +22358,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"); @@ -21899,13 +22369,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; } @@ -21914,14 +22384,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"); @@ -21937,7 +22407,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"); @@ -21946,7 +22416,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); @@ -21960,13 +22430,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; } @@ -21979,21 +22452,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; @@ -22007,8 +22480,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[] = { @@ -22024,7 +22497,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, @@ -22055,14 +22528,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"); @@ -22078,7 +22551,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"); @@ -22087,7 +22560,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); @@ -22101,13 +22574,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; } @@ -22120,21 +22596,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; @@ -22148,8 +22624,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[] = { @@ -22164,7 +22640,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, @@ -22195,14 +22671,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"); @@ -22218,7 +22694,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"); @@ -22227,7 +22703,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); @@ -22241,13 +22717,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; } @@ -22260,21 +22739,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; @@ -22288,8 +22767,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[] = { @@ -22304,7 +22783,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, @@ -22335,14 +22814,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"); @@ -22358,7 +22837,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"); @@ -22367,7 +22846,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); @@ -22381,13 +22860,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; } @@ -22400,21 +22882,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; @@ -22428,8 +22910,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[] = { @@ -22444,7 +22926,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, @@ -22475,14 +22957,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"); @@ -22498,7 +22980,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"); @@ -22507,7 +22989,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); @@ -22521,13 +23003,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; } @@ -22540,21 +23025,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; @@ -22568,8 +23053,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[] = { @@ -22584,7 +23069,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, @@ -22615,14 +23100,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"); @@ -22638,7 +23123,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"); @@ -22647,7 +23132,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); @@ -22661,13 +23146,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; } @@ -22680,21 +23168,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; @@ -22708,8 +23196,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[] = { @@ -22724,7 +23212,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, @@ -22755,14 +23243,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"); @@ -22778,7 +23266,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"); @@ -22787,7 +23275,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); @@ -22801,13 +23289,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; } @@ -22820,21 +23311,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; @@ -22848,8 +23339,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[] = { @@ -22864,7 +23355,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, @@ -22895,14 +23386,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"); @@ -22918,7 +23409,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"); @@ -22927,7 +23418,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); @@ -22941,13 +23432,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; } @@ -22960,21 +23454,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; @@ -22988,8 +23482,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[] = { @@ -23004,7 +23498,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, @@ -23035,14 +23529,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"); @@ -23058,7 +23552,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"); @@ -23067,7 +23561,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); @@ -23081,13 +23575,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; } @@ -23100,21 +23597,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; @@ -23128,8 +23625,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[] = { @@ -23144,7 +23641,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, @@ -23175,14 +23672,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"); @@ -23198,7 +23695,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"); @@ -23207,7 +23704,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); @@ -23221,13 +23718,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; } @@ -23240,21 +23740,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; @@ -23268,8 +23768,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[] = { @@ -23284,7 +23784,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, @@ -23315,14 +23815,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"); @@ -23338,7 +23838,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"); @@ -23347,7 +23847,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); @@ -23361,13 +23861,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; } @@ -23380,21 +23883,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; @@ -23408,8 +23911,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[] = { @@ -23424,7 +23927,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, @@ -23455,14 +23958,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"); @@ -23478,7 +23981,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"); @@ -23487,7 +23990,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); @@ -23501,13 +24004,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; } @@ -23520,21 +24026,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; @@ -23548,8 +24054,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[] = { @@ -23564,7 +24070,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, @@ -23595,14 +24101,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"); @@ -23618,7 +24124,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"); @@ -23627,7 +24133,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); @@ -23641,13 +24147,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; } @@ -23660,21 +24169,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; @@ -23688,8 +24197,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[] = { @@ -23704,7 +24213,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, @@ -23735,14 +24244,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"); @@ -23758,7 +24267,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"); @@ -23767,7 +24276,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); @@ -23781,13 +24290,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; } @@ -23800,21 +24312,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; @@ -23828,8 +24340,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[] = { @@ -23844,7 +24356,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, @@ -23875,14 +24387,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"); @@ -23898,7 +24410,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"); @@ -23907,7 +24419,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); @@ -23921,13 +24433,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; } @@ -23940,21 +24455,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; @@ -23968,8 +24483,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[] = { @@ -23984,7 +24499,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, @@ -24015,14 +24530,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"); @@ -24038,7 +24553,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"); @@ -24047,7 +24562,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); @@ -24061,13 +24576,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; } @@ -24080,21 +24598,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; @@ -24108,8 +24626,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[] = { @@ -24124,7 +24642,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, @@ -24160,7 +24678,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; @@ -24174,8 +24692,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[] = { @@ -24186,7 +24704,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, @@ -24217,6 +24735,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; @@ -24228,7 +24747,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"); @@ -24237,7 +24756,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); @@ -24251,13 +24770,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; } @@ -24268,7 +24790,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; @@ -24282,8 +24804,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[] = { @@ -24297,7 +24819,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, @@ -24328,6 +24850,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; @@ -24339,7 +24862,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"); @@ -24348,7 +24871,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); @@ -24362,13 +24885,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; } @@ -24379,7 +24905,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; @@ -24393,8 +24919,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[] = { @@ -24408,7 +24934,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, @@ -24439,6 +24965,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; @@ -24450,7 +24977,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"); @@ -24459,7 +24986,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); @@ -24473,13 +25000,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; } @@ -24490,7 +25020,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; @@ -24504,8 +25034,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[] = { @@ -24519,7 +25049,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, @@ -24550,20 +25080,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; } @@ -24572,7 +25102,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(); @@ -24585,12 +25115,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; @@ -24602,7 +25132,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"); @@ -24611,7 +25141,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); @@ -24625,13 +25155,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; } @@ -24642,7 +25175,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; @@ -24656,8 +25189,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[] = { @@ -24672,7 +25205,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, @@ -24703,20 +25236,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; } @@ -24725,11 +25258,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; @@ -24741,7 +25274,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"); @@ -24750,7 +25283,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); @@ -24764,13 +25297,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; } @@ -24781,7 +25317,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; @@ -24795,8 +25331,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[] = { @@ -24811,7 +25347,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, @@ -24842,20 +25378,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; } @@ -24864,11 +25400,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; @@ -24880,7 +25416,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"); @@ -24889,7 +25425,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); @@ -24903,13 +25439,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; } @@ -24920,7 +25459,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; @@ -24934,8 +25473,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[] = { @@ -24950,7 +25489,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, @@ -24981,20 +25520,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; } @@ -25003,11 +25542,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; @@ -25019,7 +25558,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"); @@ -25028,7 +25567,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); @@ -25042,13 +25581,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; } @@ -25059,7 +25601,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; @@ -25073,8 +25615,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[] = { @@ -25089,7 +25631,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, @@ -25120,13 +25662,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; } @@ -25135,7 +25678,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); @@ -25149,13 +25692,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; } @@ -25166,7 +25712,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; @@ -25180,8 +25726,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[] = { @@ -25193,7 +25739,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, @@ -25224,7 +25770,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); @@ -25238,13 +25784,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; } @@ -25255,7 +25804,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; @@ -25269,8 +25818,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[] = { @@ -25281,7 +25830,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, @@ -25312,7 +25861,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"); @@ -25327,7 +25877,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; } @@ -25336,22 +25886,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; } @@ -25365,7 +25915,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; @@ -25379,8 +25929,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[] = { @@ -25393,7 +25943,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, @@ -25424,7 +25974,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -25439,7 +25990,7 @@ bool js_cocos2dx_Grid3DAction_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; } @@ -25453,7 +26004,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; @@ -25467,8 +26018,8 @@ 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[] = { @@ -25480,7 +26031,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, @@ -25511,7 +26062,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -25526,7 +26078,7 @@ bool js_cocos2dx_TiledGrid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -25540,7 +26092,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; @@ -25554,8 +26106,8 @@ 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[] = { @@ -25567,7 +26119,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, @@ -25598,6 +26150,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; @@ -25609,7 +26162,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"); @@ -25618,7 +26171,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); @@ -25632,13 +26185,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; } @@ -25649,7 +26205,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; @@ -25663,8 +26219,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[] = { @@ -25678,7 +26234,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, @@ -25709,20 +26265,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; } @@ -25731,11 +26287,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; @@ -25747,7 +26303,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"); @@ -25756,7 +26312,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); @@ -25770,13 +26326,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; } @@ -25787,7 +26346,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; @@ -25801,8 +26360,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[] = { @@ -25817,7 +26376,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, @@ -25848,18 +26407,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; } @@ -25868,9 +26427,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"); @@ -25879,15 +26438,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; } @@ -25896,7 +26455,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"); @@ -25904,7 +26464,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; } @@ -25913,7 +26473,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"); @@ -25921,7 +26482,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; } @@ -25930,18 +26491,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; } @@ -25950,17 +26511,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; @@ -25972,7 +26533,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"); @@ -25981,7 +26542,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); @@ -25995,13 +26556,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; } @@ -26012,7 +26576,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; @@ -26026,8 +26590,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[] = { @@ -26046,7 +26610,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, @@ -26077,22 +26641,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; } @@ -26101,20 +26665,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; } @@ -26123,11 +26687,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; @@ -26139,7 +26703,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"); @@ -26148,7 +26712,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); @@ -26162,13 +26726,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; } @@ -26179,7 +26746,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; @@ -26193,8 +26760,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[] = { @@ -26210,7 +26777,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, @@ -26241,11 +26808,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; @@ -26257,7 +26824,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"); @@ -26266,7 +26833,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); @@ -26280,13 +26847,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; } @@ -26297,7 +26867,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; @@ -26311,8 +26881,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[] = { @@ -26326,7 +26896,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, @@ -26357,18 +26927,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; } @@ -26377,9 +26947,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"); @@ -26388,15 +26958,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; } @@ -26405,18 +26975,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; } @@ -26425,7 +26995,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"); @@ -26433,7 +27004,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; } @@ -26442,18 +27013,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; } @@ -26462,7 +27033,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"); @@ -26470,7 +27042,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; } @@ -26479,17 +27051,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; @@ -26501,7 +27073,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"); @@ -26510,7 +27082,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); @@ -26524,13 +27096,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; } @@ -26541,7 +27116,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; @@ -26555,8 +27130,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[] = { @@ -26576,7 +27151,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, @@ -26607,18 +27182,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; } @@ -26627,9 +27202,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"); @@ -26640,17 +27215,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; } @@ -26659,7 +27234,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"); @@ -26667,7 +27243,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; } @@ -26676,18 +27252,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; } @@ -26696,7 +27272,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"); @@ -26704,7 +27281,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; } @@ -26713,18 +27290,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; } @@ -26733,7 +27310,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"); @@ -26741,7 +27319,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; } @@ -26750,7 +27328,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; @@ -26759,12 +27337,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; @@ -26776,7 +27354,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"); @@ -26785,7 +27363,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); @@ -26799,13 +27377,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; } @@ -26816,7 +27397,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; @@ -26830,8 +27411,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[] = { @@ -26852,7 +27433,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, @@ -26883,9 +27464,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"); @@ -26894,15 +27475,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; } @@ -26911,17 +27492,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; @@ -26933,7 +27514,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"); @@ -26942,7 +27523,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); @@ -26956,13 +27537,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; } @@ -26973,7 +27557,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; @@ -26987,8 +27571,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[] = { @@ -27003,7 +27587,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, @@ -27034,18 +27618,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; } @@ -27054,9 +27638,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"); @@ -27065,15 +27649,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; } @@ -27082,7 +27666,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"); @@ -27090,7 +27675,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; } @@ -27099,7 +27684,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"); @@ -27107,7 +27693,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; } @@ -27116,18 +27702,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; } @@ -27136,17 +27722,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; @@ -27158,7 +27744,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"); @@ -27167,7 +27753,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); @@ -27181,13 +27767,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; } @@ -27198,7 +27787,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; @@ -27212,8 +27801,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[] = { @@ -27232,7 +27821,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, @@ -27263,18 +27852,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; } @@ -27283,9 +27872,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"); @@ -27296,17 +27885,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; } @@ -27315,7 +27904,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"); @@ -27323,7 +27913,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; } @@ -27332,7 +27922,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"); @@ -27340,7 +27931,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; } @@ -27349,18 +27940,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; } @@ -27369,7 +27960,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; @@ -27378,12 +27969,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; @@ -27395,7 +27986,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"); @@ -27404,7 +27995,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); @@ -27418,13 +28009,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; } @@ -27435,7 +28029,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; @@ -27449,8 +28043,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[] = { @@ -27469,7 +28063,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, @@ -27500,18 +28094,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; } @@ -27520,9 +28114,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"); @@ -27532,16 +28126,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; } @@ -27550,7 +28144,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"); @@ -27558,7 +28153,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; } @@ -27567,18 +28162,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; } @@ -27587,7 +28182,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"); @@ -27595,7 +28191,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; } @@ -27604,18 +28200,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; } @@ -27624,7 +28220,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"); @@ -27632,7 +28229,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; } @@ -27641,7 +28238,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; @@ -27649,11 +28246,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; @@ -27665,7 +28262,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"); @@ -27674,7 +28271,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); @@ -27688,13 +28285,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; } @@ -27705,7 +28305,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; @@ -27719,8 +28319,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[] = { @@ -27741,7 +28341,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, @@ -27772,7 +28372,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -27787,7 +28388,7 @@ bool js_cocos2dx_PageTurn3D_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; } @@ -27796,13 +28397,13 @@ bool js_cocos2dx_PageTurn3D_getGrid(JSContext *cx, uint32_t argc, jsval *vp) } 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; @@ -27814,7 +28415,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"); @@ -27828,7 +28429,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; @@ -27842,8 +28443,8 @@ 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[] = { @@ -27858,7 +28459,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, @@ -27889,22 +28490,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; } @@ -27913,13 +28514,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; @@ -27931,7 +28532,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"); @@ -27940,7 +28541,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); @@ -27954,13 +28555,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; } @@ -27971,7 +28575,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; @@ -27985,8 +28589,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[] = { @@ -28001,7 +28605,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, @@ -28032,9 +28636,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"); @@ -28042,14 +28646,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; } @@ -28058,15 +28662,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; @@ -28078,7 +28682,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"); @@ -28087,7 +28691,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); @@ -28101,13 +28705,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; } @@ -28118,7 +28725,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; @@ -28132,8 +28739,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[] = { @@ -28148,7 +28755,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, @@ -28179,9 +28786,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"); @@ -28190,15 +28797,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; } @@ -28207,17 +28814,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; @@ -28229,7 +28836,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"); @@ -28238,7 +28845,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); @@ -28252,13 +28859,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; } @@ -28269,7 +28879,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; @@ -28283,8 +28893,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[] = { @@ -28299,7 +28909,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, @@ -28330,9 +28940,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"); @@ -28341,15 +28951,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; } @@ -28358,17 +28968,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; @@ -28380,7 +28990,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"); @@ -28389,7 +28999,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); @@ -28403,13 +29013,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; } @@ -28420,7 +29033,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; @@ -28434,8 +29047,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[] = { @@ -28450,7 +29063,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, @@ -28481,21 +29094,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; } @@ -28504,9 +29117,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"); @@ -28515,10 +29128,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; } @@ -28527,9 +29140,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"); @@ -28537,14 +29150,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; } @@ -28553,20 +29166,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; } @@ -28575,15 +29188,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; @@ -28595,7 +29208,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"); @@ -28604,7 +29217,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); @@ -28618,13 +29231,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; } @@ -28635,7 +29251,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; @@ -28649,8 +29265,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[] = { @@ -28668,7 +29284,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, @@ -28699,18 +29315,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; } @@ -28719,18 +29335,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; } @@ -28739,20 +29355,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; } @@ -28761,22 +29377,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; } @@ -28785,13 +29401,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; @@ -28803,7 +29419,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"); @@ -28812,7 +29428,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); @@ -28826,13 +29442,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; } @@ -28843,7 +29462,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; @@ -28857,8 +29476,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[] = { @@ -28876,7 +29495,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, @@ -28907,13 +29526,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; @@ -28925,7 +29544,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"); @@ -28934,7 +29553,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); @@ -28948,13 +29567,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; } @@ -28965,7 +29587,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; @@ -28979,8 +29601,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[] = { @@ -28994,7 +29616,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, @@ -29025,20 +29647,20 @@ JSObject *jsb_cocos2d_FadeOutUpTiles_prototype; bool js_cocos2dx_FadeOutUpTiles_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::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); + 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_FadeOutUpTiles_transformTile : Error processing arguments"); cobj->transformTile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -29047,13 +29669,13 @@ bool js_cocos2dx_FadeOutUpTiles_transformTile(JSContext *cx, uint32_t argc, jsva } 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; @@ -29065,7 +29687,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"); @@ -29074,7 +29696,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); @@ -29088,13 +29710,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; } @@ -29105,7 +29730,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; @@ -29119,8 +29744,8 @@ 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[] = { @@ -29135,7 +29760,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, @@ -29166,13 +29791,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; @@ -29184,7 +29809,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"); @@ -29193,7 +29818,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); @@ -29207,13 +29832,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; } @@ -29224,7 +29852,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; @@ -29238,8 +29866,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[] = { @@ -29253,7 +29881,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, @@ -29284,18 +29912,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; } @@ -29304,18 +29932,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; } @@ -29324,9 +29952,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"); @@ -29335,10 +29963,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; } @@ -29347,9 +29975,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"); @@ -29357,14 +29985,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; } @@ -29373,19 +30001,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; @@ -29397,7 +30025,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); @@ -29405,10 +30033,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; @@ -29420,7 +30048,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); @@ -29429,7 +30057,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); @@ -29443,13 +30071,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; } @@ -29460,7 +30091,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; @@ -29474,8 +30105,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[] = { @@ -29493,7 +30124,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, @@ -29524,18 +30155,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; } @@ -29544,9 +30175,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"); @@ -29555,15 +30186,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; } @@ -29572,7 +30203,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"); @@ -29580,7 +30212,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; } @@ -29589,7 +30221,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"); @@ -29597,7 +30230,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; } @@ -29606,18 +30239,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; } @@ -29626,17 +30259,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; @@ -29648,7 +30281,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"); @@ -29657,7 +30290,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); @@ -29671,13 +30304,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; } @@ -29688,7 +30324,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; @@ -29702,8 +30338,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[] = { @@ -29722,7 +30358,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, @@ -29753,18 +30389,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; } @@ -29773,9 +30409,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"); @@ -29784,15 +30420,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; } @@ -29801,7 +30437,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"); @@ -29809,7 +30446,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; } @@ -29818,7 +30455,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"); @@ -29826,7 +30464,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; } @@ -29835,18 +30473,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; } @@ -29855,17 +30493,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; @@ -29877,7 +30515,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"); @@ -29886,7 +30524,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); @@ -29900,13 +30538,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; } @@ -29917,7 +30558,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; @@ -29931,8 +30572,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[] = { @@ -29951,7 +30592,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, @@ -29982,22 +30623,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; } @@ -30006,13 +30647,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; @@ -30024,7 +30665,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"); @@ -30033,7 +30674,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); @@ -30047,13 +30688,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; } @@ -30064,7 +30708,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; @@ -30078,8 +30722,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[] = { @@ -30094,7 +30738,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, @@ -30125,22 +30769,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; } @@ -30149,13 +30793,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; @@ -30167,7 +30811,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"); @@ -30176,7 +30820,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); @@ -30190,13 +30834,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; } @@ -30207,7 +30854,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; @@ -30221,8 +30868,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[] = { @@ -30237,7 +30884,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, @@ -30268,9 +30915,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"); @@ -30279,15 +30926,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; } @@ -30296,17 +30943,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; @@ -30318,7 +30965,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"); @@ -30334,21 +30981,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; @@ -30362,8 +31009,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[] = { @@ -30379,7 +31026,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, @@ -30410,7 +31057,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"); @@ -30425,7 +31073,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; } @@ -30434,18 +31082,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; } @@ -30454,7 +31102,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); @@ -30468,13 +31116,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; } @@ -30485,7 +31136,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; @@ -30499,8 +31150,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[] = { @@ -30513,7 +31164,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, @@ -30544,7 +31195,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); @@ -30558,13 +31209,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; } @@ -30575,7 +31229,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; @@ -30589,8 +31243,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[] = { @@ -30601,7 +31255,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, @@ -30637,7 +31291,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; @@ -30651,8 +31305,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[] = { @@ -30663,7 +31317,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, @@ -30699,7 +31353,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; @@ -30713,8 +31367,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[] = { @@ -30725,7 +31379,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, @@ -30756,12 +31410,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"); @@ -30769,19 +31423,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); @@ -30790,16 +31444,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); @@ -30808,22 +31462,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); @@ -30833,13 +31487,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; } @@ -30848,28 +31503,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; } @@ -30878,9 +31533,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"); @@ -30888,17 +31543,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; } @@ -30907,18 +31562,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; } @@ -30927,13 +31582,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; } @@ -30942,13 +31598,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; } @@ -30957,15 +31614,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; @@ -30977,7 +31634,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; } @@ -30986,42 +31643,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; } @@ -31030,13 +31687,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; } @@ -31045,6 +31703,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; @@ -31056,7 +31715,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"); @@ -31065,7 +31724,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); @@ -31079,13 +31738,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; } @@ -31096,7 +31758,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; @@ -31110,8 +31772,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[] = { @@ -31135,7 +31797,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, @@ -31166,25 +31828,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); @@ -31192,20 +31854,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); @@ -31213,20 +31875,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); @@ -31234,13 +31896,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); @@ -31250,25 +31912,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); @@ -31276,13 +31938,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); @@ -31292,13 +31954,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; } @@ -31307,25 +31970,25 @@ 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]; @@ -31345,8 +32008,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); } @@ -31361,7 +32024,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); @@ -31369,13 +32032,13 @@ 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]; @@ -31395,8 +32058,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); } @@ -31411,7 +32074,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); @@ -31421,18 +32084,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; } @@ -31441,7 +32104,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"); @@ -31449,7 +32113,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; } @@ -31458,23 +32122,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; } @@ -31483,25 +32147,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); @@ -31509,13 +32173,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); @@ -31525,25 +32189,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); @@ -31551,13 +32215,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); @@ -31567,25 +32231,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); @@ -31593,13 +32257,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); @@ -31609,7 +32273,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"); @@ -31617,7 +32282,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; } @@ -31626,25 +32291,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; } @@ -31653,25 +32318,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); @@ -31679,13 +32344,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); @@ -31695,7 +32360,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"); @@ -31703,7 +32369,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; } @@ -31712,20 +32378,20 @@ 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]; @@ -31737,8 +32403,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); } @@ -31753,7 +32419,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; } @@ -31762,58 +32428,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"); @@ -31828,7 +32464,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; } @@ -31837,14 +32473,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"); @@ -31860,7 +32496,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"); @@ -31869,11 +32505,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; @@ -31885,7 +32521,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"); @@ -31894,14 +32530,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"); @@ -31917,7 +32553,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"); @@ -31930,7 +32566,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; @@ -31944,8 +32580,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[] = { @@ -31965,7 +32601,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 }; @@ -31979,7 +32614,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, @@ -32010,13 +32645,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; } @@ -32025,9 +32661,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"); @@ -32036,15 +32672,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; } @@ -32053,7 +32689,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"); @@ -32068,7 +32705,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; } @@ -32077,25 +32714,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; } @@ -32104,18 +32741,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; } @@ -32124,7 +32761,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"); @@ -32139,7 +32777,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; } @@ -32148,7 +32786,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"); @@ -32156,7 +32795,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; } @@ -32165,7 +32804,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"); @@ -32173,7 +32813,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; } @@ -32182,25 +32822,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; } @@ -32209,9 +32849,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"); @@ -32221,21 +32861,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; } @@ -32244,18 +32884,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; } @@ -32264,17 +32904,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; @@ -32286,7 +32926,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"); @@ -32295,7 +32935,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); @@ -32309,13 +32949,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; } @@ -32326,7 +32969,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; @@ -32340,8 +32983,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[] = { @@ -32366,7 +33009,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, @@ -32397,9 +33040,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"); @@ -32407,12 +33050,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; } @@ -32421,12 +33064,12 @@ 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 = 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_drawPoints : Invalid Native Object"); @@ -32434,25 +33077,25 @@ bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 4) { const cocos2d::Vec2* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } 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); 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; } 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::Color4F arg3; - ok &= jsval_to_cccolor4f(cx, argv[3], &arg3); + ok &= jsval_to_cccolor4f(cx, args.get(3), &arg3); if (!ok) { ok = true; break; } cobj->drawPoints(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32461,22 +33104,22 @@ bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 3) { const cocos2d::Vec2* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } 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); 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; } 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->drawPoints(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -32486,34 +33129,34 @@ bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp) } 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); @@ -32521,16 +33164,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); @@ -32540,34 +33183,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); @@ -32575,28 +33218,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); @@ -32606,20 +33249,20 @@ 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; } @@ -32628,7 +33271,8 @@ bool js_cocos2dx_DrawNode_onDrawGLPoint(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_DrawNode_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::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_init : Invalid Native Object"); @@ -32636,7 +33280,7 @@ bool js_cocos2dx_DrawNode_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; } @@ -32645,9 +33289,9 @@ bool js_cocos2dx_DrawNode_init(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -32655,12 +33299,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; } @@ -32669,9 +33313,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"); @@ -32680,18 +33324,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; } @@ -32700,9 +33344,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"); @@ -32711,13 +33355,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; } @@ -32726,7 +33370,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"); @@ -32734,7 +33379,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; } @@ -32743,20 +33388,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; } @@ -32765,36 +33410,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); @@ -32802,30 +33447,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); @@ -32835,9 +33480,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"); @@ -32847,14 +33492,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; } @@ -32863,20 +33508,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; } @@ -32885,9 +33530,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"); @@ -32896,18 +33541,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; } @@ -32916,9 +33561,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"); @@ -32927,13 +33572,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; } @@ -32942,18 +33587,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; } @@ -32962,13 +33607,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; } @@ -32977,9 +33623,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"); @@ -32989,19 +33635,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; } @@ -33010,9 +33656,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"); @@ -33020,12 +33666,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; } @@ -33034,9 +33680,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"); @@ -33046,19 +33692,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; } @@ -33067,9 +33713,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"); @@ -33077,12 +33723,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; } @@ -33091,9 +33737,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"); @@ -33104,15 +33750,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; } @@ -33121,6 +33767,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; @@ -33132,7 +33779,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"); @@ -33141,7 +33788,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); @@ -33155,13 +33802,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; } @@ -33174,21 +33824,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; @@ -33202,8 +33852,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[] = { @@ -33241,7 +33891,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, @@ -33272,18 +33922,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; } @@ -33292,27 +33942,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); @@ -33320,24 +33970,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); @@ -33345,31 +33995,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); @@ -33379,13 +34029,14 @@ bool js_cocos2dx_LabelAtlas_initWithString(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_LabelAtlas_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::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); + args.rval().setUndefined(); return true; } @@ -33394,7 +34045,8 @@ bool js_cocos2dx_LabelAtlas_updateAtlasValues(JSContext *cx, uint32_t argc, jsva } 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"); @@ -33402,7 +34054,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; } @@ -33411,25 +34063,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; @@ -33441,7 +34093,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); @@ -33458,7 +34110,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); @@ -33466,10 +34118,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; @@ -33481,7 +34133,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); @@ -33490,7 +34142,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); @@ -33504,13 +34156,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; } @@ -33523,21 +34178,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; @@ -33551,8 +34206,8 @@ 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[] = { @@ -33571,7 +34226,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, @@ -33602,9 +34257,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"); @@ -33612,12 +34267,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) { @@ -33625,13 +34280,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; } @@ -33640,18 +34295,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; } @@ -33660,7 +34315,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"); @@ -33668,7 +34324,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; } @@ -33677,7 +34333,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"); @@ -33685,7 +34342,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; } @@ -33694,18 +34351,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; } @@ -33714,18 +34371,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; } @@ -33734,18 +34391,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; } @@ -33754,18 +34411,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; } @@ -33774,7 +34431,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"); @@ -33782,7 +34440,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; } @@ -33791,22 +34449,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; } @@ -33815,18 +34473,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; } @@ -33835,9 +34493,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"); @@ -33845,14 +34503,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) { @@ -33860,15 +34518,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) { @@ -33877,16 +34535,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) { @@ -33896,17 +34554,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; } @@ -33915,28 +34573,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; } @@ -33945,7 +34603,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"); @@ -33953,7 +34612,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; } @@ -33962,32 +34621,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; } @@ -33996,7 +34655,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"); @@ -34004,7 +34664,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; } @@ -34013,18 +34673,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; } @@ -34033,18 +34693,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; } @@ -34053,7 +34713,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"); @@ -34061,7 +34722,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; } @@ -34070,7 +34731,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"); @@ -34078,7 +34740,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; } @@ -34087,18 +34749,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; } @@ -34107,7 +34769,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"); @@ -34115,7 +34778,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; } @@ -34124,18 +34787,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; } @@ -34144,23 +34807,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; } @@ -34169,23 +34832,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; } @@ -34194,7 +34857,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 { @@ -34209,7 +34872,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); @@ -34217,13 +34880,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; @@ -34235,23 +34898,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; @@ -34263,26 +34926,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; @@ -34294,29 +34957,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; @@ -34328,7 +34991,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); @@ -34337,13 +35000,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; @@ -34355,7 +35018,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"); @@ -34364,7 +35027,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); @@ -34378,13 +35041,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; } @@ -34397,21 +35063,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; @@ -34425,8 +35091,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[] = { @@ -34467,7 +35133,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, @@ -34498,25 +35164,25 @@ 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; } @@ -34525,18 +35191,18 @@ bool js_cocos2dx_SpriteBatchNode_appendChild(JSContext *cx, uint32_t argc, jsval } 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; } @@ -34545,7 +35211,8 @@ bool js_cocos2dx_SpriteBatchNode_reorderBatch(JSContext *cx, uint32_t argc, jsva } 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"); @@ -34560,7 +35227,7 @@ 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; } @@ -34569,25 +35236,25 @@ bool js_cocos2dx_SpriteBatchNode_getTexture(JSContext *cx, uint32_t argc, jsval } 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; } @@ -34596,20 +35263,20 @@ bool js_cocos2dx_SpriteBatchNode_setTexture(JSContext *cx, uint32_t argc, jsval } 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_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])); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34618,25 +35285,25 @@ bool js_cocos2dx_SpriteBatchNode_removeChildAtIndex(JSContext *cx, uint32_t argc } 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_removeSpriteFromAtlas : 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_removeSpriteFromAtlas : Error processing arguments"); cobj->removeSpriteFromAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34645,9 +35312,9 @@ bool js_cocos2dx_SpriteBatchNode_removeSpriteFromAtlas(JSContext *cx, uint32_t a } bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_addSpriteWithoutQuad : Invalid Native Object"); @@ -34656,15 +35323,15 @@ bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t ar int arg1; int 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); - 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(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; @@ -34676,7 +35343,7 @@ bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -34685,9 +35352,9 @@ bool js_cocos2dx_SpriteBatchNode_addSpriteWithoutQuad(JSContext *cx, uint32_t ar } bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); @@ -34695,19 +35362,19 @@ bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc cocos2d::Sprite* 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::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, 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -34716,13 +35383,14 @@ bool js_cocos2dx_SpriteBatchNode_atlasIndexForChild(JSContext *cx, uint32_t argc } bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34731,7 +35399,8 @@ bool js_cocos2dx_SpriteBatchNode_increaseAtlasCapacity(JSContext *cx, uint32_t a } bool js_cocos2dx_SpriteBatchNode_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::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_init : Invalid Native Object"); @@ -34739,7 +35408,7 @@ bool js_cocos2dx_SpriteBatchNode_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; } @@ -34748,18 +35417,18 @@ bool js_cocos2dx_SpriteBatchNode_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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"); @@ -34768,7 +35437,7 @@ bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t ssize_t ret = cobj->lowestAtlasIndexInChild(arg0); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -34777,7 +35446,8 @@ bool js_cocos2dx_SpriteBatchNode_lowestAtlasIndexInChild(JSContext *cx, uint32_t } bool js_cocos2dx_SpriteBatchNode_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::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getBlendFunc : Invalid Native Object"); @@ -34785,7 +35455,7 @@ bool js_cocos2dx_SpriteBatchNode_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; } @@ -34794,9 +35464,9 @@ bool js_cocos2dx_SpriteBatchNode_getBlendFunc(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_SpriteBatchNode_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::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_initWithTexture : Invalid Native Object"); @@ -34804,19 +35474,19 @@ bool js_cocos2dx_SpriteBatchNode_initWithTexture(JSContext *cx, uint32_t argc, j 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_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; } @@ -34825,25 +35495,25 @@ bool js_cocos2dx_SpriteBatchNode_initWithTexture(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_SpriteBatchNode_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::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 (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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_SpriteBatchNode_setTextureAtlas : Error processing arguments"); cobj->setTextureAtlas(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34852,9 +35522,9 @@ bool js_cocos2dx_SpriteBatchNode_setTextureAtlas(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_insertQuadFromSprite : Invalid Native Object"); @@ -34862,17 +35532,17 @@ bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t ar 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -34881,22 +35551,22 @@ bool js_cocos2dx_SpriteBatchNode_insertQuadFromSprite(JSContext *cx, uint32_t ar } bool js_cocos2dx_SpriteBatchNode_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::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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -34905,18 +35575,18 @@ bool js_cocos2dx_SpriteBatchNode_initWithFile(JSContext *cx, uint32_t argc, jsva } 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; } @@ -34925,9 +35595,9 @@ bool js_cocos2dx_SpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsva } 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_rebuildIndexInOrder : Invalid Native Object"); @@ -34935,19 +35605,19 @@ bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t arg 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); + 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); + args.rval().set(jsret); return true; } @@ -34956,7 +35626,8 @@ bool js_cocos2dx_SpriteBatchNode_rebuildIndexInOrder(JSContext *cx, uint32_t arg } bool js_cocos2dx_SpriteBatchNode_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::SpriteBatchNode* cobj = (cocos2d::SpriteBatchNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_SpriteBatchNode_getTextureAtlas : Invalid Native Object"); @@ -34971,7 +35642,7 @@ bool js_cocos2dx_SpriteBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, j jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -34980,18 +35651,18 @@ bool js_cocos2dx_SpriteBatchNode_getTextureAtlas(JSContext *cx, uint32_t argc, j } 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_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"); @@ -35000,7 +35671,7 @@ bool js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild(JSContext *cx, uint32_ 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; } @@ -35009,11 +35680,11 @@ bool js_cocos2dx_SpriteBatchNode_highestAtlasIndexInChild(JSContext *cx, uint32_ } 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; @@ -35025,14 +35696,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; @@ -35044,7 +35715,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"); @@ -35053,14 +35724,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"); @@ -35076,21 +35747,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; @@ -35102,7 +35773,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"); @@ -35111,7 +35782,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); @@ -35125,13 +35796,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; } @@ -35144,21 +35818,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; @@ -35172,8 +35846,8 @@ 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[] = { @@ -35209,7 +35883,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, @@ -35240,7 +35914,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"); @@ -35248,7 +35923,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; } @@ -35257,45 +35932,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; } @@ -35304,20 +35979,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) { 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_Label_setDimensions : Error processing arguments"); cobj->setDimensions(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35326,7 +36001,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"); @@ -35334,7 +36010,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; } @@ -35343,7 +36019,8 @@ 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"); @@ -35351,7 +36028,7 @@ bool js_cocos2dx_Label_getHeight(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getHeight(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35360,13 +36037,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; } @@ -35375,7 +36053,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"); @@ -35383,7 +36062,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; } @@ -35392,18 +36071,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) { 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_setWidth : Error processing arguments"); cobj->setWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35412,7 +36091,8 @@ 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"); @@ -35420,7 +36100,7 @@ bool js_cocos2dx_Label_getMaxLineWidth(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getMaxLineWidth(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35429,7 +36109,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"); @@ -35437,7 +36118,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; } @@ -35446,18 +36127,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; } @@ -35466,18 +36147,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; } @@ -35486,18 +36167,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; } @@ -35506,32 +36187,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; } @@ -35540,18 +36221,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; } @@ -35560,18 +36241,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; } @@ -35580,13 +36261,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; } @@ -35595,7 +36277,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"); @@ -35603,7 +36286,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; } @@ -35612,18 +36295,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; } @@ -35632,7 +36315,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"); @@ -35640,7 +36324,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; } @@ -35649,28 +36333,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; } @@ -35679,7 +36363,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"); @@ -35687,7 +36372,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; } @@ -35696,12 +36381,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"); @@ -35709,27 +36394,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); @@ -35737,21 +36422,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); @@ -35759,12 +36444,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); @@ -35774,7 +36459,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"); @@ -35782,7 +36468,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; } @@ -35791,18 +36477,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) { 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_setMaxLineWidth : Error processing arguments"); cobj->setMaxLineWidth(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35811,7 +36497,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"); @@ -35819,7 +36506,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; } @@ -35828,18 +36515,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; } @@ -35848,7 +36535,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"); @@ -35856,7 +36544,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; } @@ -35865,7 +36553,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"); @@ -35873,7 +36562,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; } @@ -35882,7 +36571,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"); @@ -35890,7 +36580,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; } @@ -35899,18 +36589,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; } @@ -35919,18 +36609,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) { 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_setHeight : Error processing arguments"); cobj->setHeight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -35939,7 +36629,8 @@ 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"); @@ -35947,7 +36638,7 @@ bool js_cocos2dx_Label_getWidth(JSContext *cx, uint32_t argc, jsval *vp) double ret = cobj->getWidth(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -35956,18 +36647,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; } @@ -35976,15 +36667,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; @@ -35996,7 +36687,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; } @@ -36005,18 +36696,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; } @@ -36025,7 +36716,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"); @@ -36033,7 +36725,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; } @@ -36042,7 +36734,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"); @@ -36050,7 +36743,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; } @@ -36059,7 +36752,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"); @@ -36067,7 +36761,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; } @@ -36076,18 +36770,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; } @@ -36096,25 +36790,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); @@ -36122,10 +36816,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); @@ -36135,13 +36829,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; } @@ -36150,13 +36845,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; @@ -36168,16 +36863,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; @@ -36189,7 +36884,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) { @@ -36197,10 +36892,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; @@ -36212,7 +36907,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) { @@ -36221,11 +36916,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; @@ -36237,7 +36932,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"); @@ -36246,6 +36941,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; @@ -36257,7 +36953,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"); @@ -36266,29 +36962,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; @@ -36300,7 +36996,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); @@ -36308,16 +37004,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; @@ -36329,7 +37025,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); @@ -36337,7 +37033,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; @@ -36349,7 +37045,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); @@ -36358,15 +37054,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; @@ -36378,7 +37074,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) { @@ -36386,10 +37082,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; @@ -36401,7 +37097,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) { @@ -36410,11 +37106,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; @@ -36426,7 +37122,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) { @@ -36436,12 +37132,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; @@ -36453,7 +37149,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"); @@ -36462,7 +37158,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); @@ -36476,13 +37172,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; } @@ -36495,21 +37194,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; @@ -36523,8 +37222,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[] = { @@ -36584,7 +37283,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, @@ -36615,18 +37314,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; } @@ -36635,7 +37334,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"); @@ -36643,7 +37343,7 @@ 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; } @@ -36652,7 +37352,8 @@ bool js_cocos2dx_LabelBMFont_getBlendFunc(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_LabelBMFont_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::LabelBMFont* cobj = (cocos2d::LabelBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LabelBMFont_isOpacityModifyRGB : Invalid Native Object"); @@ -36660,7 +37361,7 @@ bool js_cocos2dx_LabelBMFont_isOpacityModifyRGB(JSContext *cx, uint32_t argc, js 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; } @@ -36669,15 +37370,15 @@ bool js_cocos2dx_LabelBMFont_isOpacityModifyRGB(JSContext *cx, uint32_t argc, js } 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; @@ -36689,7 +37390,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; } @@ -36698,7 +37399,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"); @@ -36706,7 +37408,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; } @@ -36715,18 +37417,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; } @@ -36735,18 +37437,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; } @@ -36755,36 +37457,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) { @@ -36792,15 +37494,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) { @@ -36809,16 +37511,16 @@ 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; } @@ -36827,18 +37529,18 @@ bool js_cocos2dx_LabelBMFont_initWithString(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_LabelBMFont_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_LabelBMFont_setOpacityModifyRGB : Error processing arguments"); cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -36847,7 +37549,8 @@ bool js_cocos2dx_LabelBMFont_setOpacityModifyRGB(JSContext *cx, uint32_t argc, j } 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"); @@ -36855,7 +37558,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; } @@ -36864,28 +37567,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; } @@ -36894,18 +37597,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; } @@ -36914,18 +37617,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; } @@ -36934,7 +37637,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 { @@ -36949,7 +37652,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); @@ -36957,10 +37660,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; @@ -36972,20 +37675,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; @@ -36997,23 +37700,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; @@ -37025,26 +37728,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; @@ -37056,7 +37759,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); @@ -37065,7 +37768,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); @@ -37079,13 +37782,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; } @@ -37098,21 +37804,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; @@ -37126,8 +37832,8 @@ 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[] = { @@ -37155,7 +37861,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, @@ -37186,6 +37892,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; @@ -37197,7 +37904,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"); @@ -37206,7 +37913,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); @@ -37220,13 +37927,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; } @@ -37239,21 +37949,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; @@ -37267,8 +37977,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[] = { @@ -37283,7 +37993,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, @@ -37314,6 +38024,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; @@ -37325,7 +38036,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"); @@ -37334,7 +38045,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); @@ -37348,13 +38059,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; } @@ -37365,7 +38079,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; @@ -37379,8 +38093,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[] = { @@ -37394,7 +38108,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, @@ -37425,20 +38139,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; } @@ -37447,7 +38161,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"); @@ -37455,7 +38170,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; } @@ -37464,18 +38179,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; } @@ -37484,18 +38199,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; } @@ -37504,30 +38219,30 @@ 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) { 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; } 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); @@ -37537,7 +38252,7 @@ bool js_cocos2dx_LayerColor_initWithColor(JSContext *cx, uint32_t argc, jsval *v 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); @@ -37545,12 +38260,12 @@ bool js_cocos2dx_LayerColor_initWithColor(JSContext *cx, uint32_t argc, jsval *v 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; } 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); @@ -37560,18 +38275,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; } @@ -37580,19 +38295,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; @@ -37604,7 +38319,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); @@ -37621,7 +38336,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); @@ -37629,7 +38344,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; @@ -37641,7 +38356,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); @@ -37650,7 +38365,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); @@ -37664,13 +38379,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; } @@ -37683,21 +38401,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; @@ -37711,8 +38429,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[] = { @@ -37733,7 +38451,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, @@ -37764,7 +38482,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"); @@ -37772,7 +38491,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; } @@ -37781,7 +38500,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"); @@ -37789,7 +38509,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; } @@ -37798,7 +38518,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"); @@ -37806,7 +38527,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; } @@ -37815,18 +38536,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; } @@ -37835,18 +38556,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; } @@ -37855,18 +38576,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; } @@ -37875,18 +38596,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; } @@ -37895,7 +38616,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"); @@ -37903,7 +38625,7 @@ 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; } @@ -37912,7 +38634,8 @@ bool js_cocos2dx_LayerGradient_getVector(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_LayerGradient_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::LayerGradient* cobj = (cocos2d::LayerGradient *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerGradient_init : Invalid Native Object"); @@ -37920,7 +38643,7 @@ bool js_cocos2dx_LayerGradient_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; } @@ -37929,18 +38652,18 @@ bool js_cocos2dx_LayerGradient_init(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -37949,30 +38672,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); @@ -37980,15 +38703,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); @@ -37998,7 +38721,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"); @@ -38006,7 +38730,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; } @@ -38015,7 +38739,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"); @@ -38023,7 +38748,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; } @@ -38032,18 +38757,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; } @@ -38052,16 +38777,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; @@ -38073,7 +38798,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); @@ -38090,7 +38815,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); @@ -38098,13 +38823,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; @@ -38116,7 +38841,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); @@ -38125,7 +38850,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); @@ -38139,13 +38864,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; } @@ -38158,21 +38886,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; @@ -38186,8 +38914,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[] = { @@ -38216,7 +38944,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, @@ -38247,20 +38975,20 @@ 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; } @@ -38269,7 +38997,8 @@ bool js_cocos2dx_LayerMultiplex_initWithArray(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_LayerMultiplex_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::LayerMultiplex* cobj = (cocos2d::LayerMultiplex *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_LayerMultiplex_init : Invalid Native Object"); @@ -38277,7 +39006,7 @@ bool js_cocos2dx_LayerMultiplex_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; } @@ -38286,18 +39015,18 @@ bool js_cocos2dx_LayerMultiplex_init(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -38306,25 +39035,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; } @@ -38333,18 +39062,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; } @@ -38353,7 +39082,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); @@ -38367,13 +39096,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; } @@ -38386,21 +39118,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; @@ -38414,8 +39146,8 @@ 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[] = { @@ -38432,7 +39164,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, @@ -38463,18 +39195,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"); @@ -38490,7 +39222,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; } @@ -38503,7 +39235,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; @@ -38517,8 +39249,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[] = { @@ -38530,7 +39262,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, @@ -38561,13 +39293,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; } @@ -38576,20 +39309,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"); @@ -38598,7 +39331,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; } @@ -38607,13 +39340,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; } @@ -38622,16 +39356,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"); @@ -38647,7 +39381,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"); @@ -38656,7 +39390,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); @@ -38670,13 +39404,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; } @@ -38689,21 +39426,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; @@ -38717,8 +39454,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[] = { @@ -38736,7 +39473,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, @@ -38767,9 +39504,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"); @@ -38777,21 +39514,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; } @@ -38800,22 +39537,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; @@ -38827,7 +39564,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"); @@ -38836,7 +39573,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); @@ -38850,13 +39587,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; } @@ -38867,7 +39607,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; @@ -38881,8 +39621,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[] = { @@ -38897,7 +39637,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, @@ -38928,16 +39668,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"); @@ -38953,7 +39693,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"); @@ -38962,7 +39702,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); @@ -38976,13 +39716,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; } @@ -38993,7 +39736,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; @@ -39007,8 +39750,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[] = { @@ -39022,7 +39765,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, @@ -39053,16 +39796,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"); @@ -39078,7 +39821,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"); @@ -39087,7 +39830,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); @@ -39101,13 +39844,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; } @@ -39118,7 +39864,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; @@ -39132,8 +39878,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[] = { @@ -39147,7 +39893,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, @@ -39178,7 +39924,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"); @@ -39193,7 +39940,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; } @@ -39202,18 +39949,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"); @@ -39229,7 +39976,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; } @@ -39238,16 +39985,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"); @@ -39263,7 +40010,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"); @@ -39272,7 +40019,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); @@ -39286,13 +40033,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; } @@ -39303,7 +40053,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; @@ -39317,8 +40067,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[] = { @@ -39334,7 +40084,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, @@ -39365,16 +40115,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"); @@ -39390,7 +40140,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"); @@ -39399,7 +40149,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); @@ -39413,13 +40163,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; } @@ -39430,7 +40183,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; @@ -39444,8 +40197,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[] = { @@ -39459,7 +40212,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, @@ -39490,16 +40243,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"); @@ -39515,7 +40268,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"); @@ -39524,7 +40277,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); @@ -39538,13 +40291,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; } @@ -39555,7 +40311,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; @@ -39569,8 +40325,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[] = { @@ -39584,7 +40340,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, @@ -39615,16 +40371,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"); @@ -39640,7 +40396,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"); @@ -39649,7 +40405,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); @@ -39663,13 +40419,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; } @@ -39680,7 +40439,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; @@ -39694,8 +40453,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[] = { @@ -39709,7 +40468,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, @@ -39740,7 +40499,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"); @@ -39755,7 +40515,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; } @@ -39764,18 +40524,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"); @@ -39791,7 +40551,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; } @@ -39800,16 +40560,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"); @@ -39825,7 +40585,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"); @@ -39834,7 +40594,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); @@ -39848,13 +40608,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; } @@ -39865,7 +40628,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; @@ -39879,8 +40642,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[] = { @@ -39896,7 +40659,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, @@ -39927,7 +40690,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -39942,7 +40706,7 @@ bool js_cocos2dx_TransitionSlideInR_action(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -39951,16 +40715,16 @@ bool js_cocos2dx_TransitionSlideInR_action(JSContext *cx, uint32_t argc, jsval * } 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"); @@ -39976,7 +40740,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"); @@ -39985,7 +40749,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); @@ -39999,13 +40763,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; } @@ -40016,7 +40783,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; @@ -40030,8 +40797,8 @@ 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[] = { @@ -40046,7 +40813,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, @@ -40077,7 +40844,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -40092,7 +40860,7 @@ bool js_cocos2dx_TransitionSlideInB_action(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -40101,16 +40869,16 @@ bool js_cocos2dx_TransitionSlideInB_action(JSContext *cx, uint32_t argc, jsval * } 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"); @@ -40126,7 +40894,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"); @@ -40135,7 +40903,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); @@ -40149,13 +40917,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; } @@ -40166,7 +40937,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; @@ -40180,8 +40951,8 @@ 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[] = { @@ -40196,7 +40967,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, @@ -40227,7 +40998,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -40242,7 +41014,7 @@ bool js_cocos2dx_TransitionSlideInT_action(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -40251,16 +41023,16 @@ bool js_cocos2dx_TransitionSlideInT_action(JSContext *cx, uint32_t argc, jsval * } 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"); @@ -40276,7 +41048,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"); @@ -40285,7 +41057,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); @@ -40299,13 +41071,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; } @@ -40316,7 +41091,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; @@ -40330,8 +41105,8 @@ 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[] = { @@ -40346,7 +41121,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, @@ -40377,18 +41152,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"); @@ -40404,7 +41179,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; } @@ -40413,16 +41188,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"); @@ -40438,7 +41213,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"); @@ -40447,7 +41222,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); @@ -40461,13 +41236,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; } @@ -40478,7 +41256,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; @@ -40492,8 +41270,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[] = { @@ -40508,7 +41286,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, @@ -40539,19 +41317,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"); @@ -40567,7 +41345,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); @@ -40575,20 +41353,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; @@ -40600,7 +41378,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); @@ -40609,7 +41387,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); @@ -40623,13 +41401,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; } @@ -40640,7 +41421,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; @@ -40654,8 +41435,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[] = { @@ -40669,7 +41450,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, @@ -40700,19 +41481,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"); @@ -40728,7 +41509,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); @@ -40736,20 +41517,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; @@ -40761,7 +41542,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); @@ -40770,7 +41551,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); @@ -40784,13 +41565,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; } @@ -40801,7 +41585,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; @@ -40815,8 +41599,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[] = { @@ -40830,7 +41614,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, @@ -40861,19 +41645,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"); @@ -40889,7 +41673,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); @@ -40897,20 +41681,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; @@ -40922,7 +41706,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); @@ -40931,7 +41715,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); @@ -40945,13 +41729,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; } @@ -40962,7 +41749,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; @@ -40976,8 +41763,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[] = { @@ -40991,7 +41778,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, @@ -41022,19 +41809,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"); @@ -41050,7 +41837,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); @@ -41058,20 +41845,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; @@ -41083,7 +41870,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); @@ -41092,7 +41879,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); @@ -41106,13 +41893,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; } @@ -41123,7 +41913,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; @@ -41137,8 +41927,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[] = { @@ -41152,7 +41942,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, @@ -41183,19 +41973,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"); @@ -41211,7 +42001,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); @@ -41219,20 +42009,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; @@ -41244,7 +42034,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); @@ -41253,7 +42043,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); @@ -41267,13 +42057,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; } @@ -41284,7 +42077,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; @@ -41298,8 +42091,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[] = { @@ -41313,7 +42106,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, @@ -41344,19 +42137,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"); @@ -41372,7 +42165,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); @@ -41380,20 +42173,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; @@ -41405,7 +42198,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); @@ -41414,7 +42207,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); @@ -41428,13 +42221,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; } @@ -41445,7 +42241,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; @@ -41459,8 +42255,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[] = { @@ -41474,7 +42270,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, @@ -41505,25 +42301,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"); @@ -41532,7 +42328,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); @@ -41540,25 +42336,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); @@ -41568,19 +42364,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"); @@ -41596,7 +42392,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); @@ -41604,20 +42400,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; @@ -41629,7 +42425,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); @@ -41638,7 +42434,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); @@ -41652,13 +42448,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; } @@ -41669,7 +42468,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; @@ -41683,8 +42482,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[] = { @@ -41699,7 +42498,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, @@ -41730,16 +42529,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"); @@ -41755,7 +42554,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"); @@ -41764,7 +42563,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); @@ -41778,13 +42577,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; } @@ -41795,7 +42597,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; @@ -41809,8 +42611,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[] = { @@ -41824,7 +42626,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, @@ -41855,18 +42657,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"); @@ -41882,7 +42684,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; } @@ -41891,16 +42693,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"); @@ -41916,7 +42718,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"); @@ -41925,7 +42727,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); @@ -41939,13 +42741,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; } @@ -41956,7 +42761,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; @@ -41970,8 +42775,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[] = { @@ -41986,7 +42791,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, @@ -42017,7 +42822,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"); @@ -42032,7 +42838,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; } @@ -42041,18 +42847,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"); @@ -42068,7 +42874,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; } @@ -42077,16 +42883,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"); @@ -42102,7 +42908,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"); @@ -42111,7 +42917,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); @@ -42125,13 +42931,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; } @@ -42142,7 +42951,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; @@ -42156,8 +42965,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[] = { @@ -42173,7 +42982,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, @@ -42204,16 +43013,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"); @@ -42229,7 +43038,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"); @@ -42238,7 +43047,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); @@ -42252,13 +43061,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; } @@ -42269,7 +43081,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; @@ -42283,8 +43095,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[] = { @@ -42298,7 +43110,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, @@ -42329,18 +43141,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"); @@ -42356,7 +43168,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; } @@ -42365,15 +43177,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; @@ -42385,7 +43197,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; } @@ -42394,16 +43206,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"); @@ -42419,7 +43231,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"); @@ -42428,7 +43240,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); @@ -42442,13 +43254,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; } @@ -42459,7 +43274,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; @@ -42473,8 +43288,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[] = { @@ -42490,7 +43305,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, @@ -42521,16 +43336,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"); @@ -42546,7 +43361,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"); @@ -42555,7 +43370,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); @@ -42569,13 +43384,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; } @@ -42586,7 +43404,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; @@ -42600,8 +43418,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[] = { @@ -42615,7 +43433,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, @@ -42646,16 +43464,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"); @@ -42671,7 +43489,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"); @@ -42680,7 +43498,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); @@ -42694,13 +43512,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; } @@ -42711,7 +43532,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; @@ -42725,8 +43546,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[] = { @@ -42740,7 +43561,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, @@ -42771,16 +43592,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"); @@ -42796,7 +43617,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"); @@ -42805,7 +43626,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); @@ -42819,13 +43640,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; } @@ -42836,7 +43660,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; @@ -42850,8 +43674,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[] = { @@ -42865,7 +43689,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, @@ -42896,15 +43720,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; @@ -42916,7 +43740,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; } @@ -42925,9 +43749,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"); @@ -42935,21 +43759,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; } @@ -42958,22 +43782,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; @@ -42985,7 +43809,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"); @@ -42994,7 +43818,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); @@ -43008,13 +43832,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; } @@ -43025,7 +43852,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; @@ -43039,8 +43866,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[] = { @@ -43056,7 +43883,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, @@ -43087,16 +43914,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"); @@ -43112,7 +43939,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"); @@ -43121,7 +43948,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); @@ -43135,13 +43962,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; } @@ -43152,7 +43982,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; @@ -43166,8 +43996,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[] = { @@ -43181,7 +44011,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, @@ -43212,16 +44042,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"); @@ -43237,7 +44067,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"); @@ -43246,7 +44076,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); @@ -43260,13 +44090,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; } @@ -43277,7 +44110,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; @@ -43291,8 +44124,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[] = { @@ -43306,7 +44139,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, @@ -43337,16 +44170,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"); @@ -43362,7 +44195,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"); @@ -43371,7 +44204,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); @@ -43385,13 +44218,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; } @@ -43402,7 +44238,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; @@ -43416,8 +44252,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[] = { @@ -43431,7 +44267,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, @@ -43462,16 +44298,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"); @@ -43487,7 +44323,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"); @@ -43496,7 +44332,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); @@ -43510,13 +44346,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; } @@ -43527,7 +44366,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; @@ -43541,8 +44380,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[] = { @@ -43556,7 +44395,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, @@ -43587,16 +44426,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"); @@ -43612,7 +44451,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"); @@ -43621,7 +44460,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); @@ -43635,13 +44474,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; } @@ -43652,7 +44494,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; @@ -43666,8 +44508,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[] = { @@ -43681,7 +44523,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, @@ -43712,16 +44554,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"); @@ -43737,7 +44579,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"); @@ -43746,7 +44588,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); @@ -43760,13 +44602,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; } @@ -43777,7 +44622,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; @@ -43791,8 +44636,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[] = { @@ -43806,7 +44651,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, @@ -43837,16 +44682,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"); @@ -43862,7 +44707,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"); @@ -43871,7 +44716,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); @@ -43885,13 +44730,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; } @@ -43902,7 +44750,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; @@ -43916,8 +44764,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[] = { @@ -43931,7 +44779,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, @@ -43962,18 +44810,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; } @@ -43982,13 +44830,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; } @@ -43997,18 +44846,18 @@ 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]; @@ -44020,8 +44869,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); } @@ -44038,7 +44887,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; } @@ -44047,7 +44896,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"); @@ -44055,7 +44905,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; } @@ -44064,13 +44914,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; } @@ -44079,7 +44930,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"); @@ -44087,7 +44939,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; } @@ -44096,13 +44948,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; } @@ -44111,7 +44964,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"); @@ -44119,7 +44973,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; } @@ -44128,7 +44982,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); @@ -44142,13 +44996,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; } @@ -44161,21 +45018,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; @@ -44189,8 +45046,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[] = { @@ -44210,7 +45067,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, @@ -44241,25 +45098,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; } @@ -44268,7 +45125,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"); @@ -44276,7 +45134,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; } @@ -44285,18 +45143,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; } @@ -44305,9 +45163,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"); @@ -44315,17 +45173,17 @@ 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]; @@ -44337,8 +45195,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); } @@ -44355,7 +45213,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; } @@ -44364,18 +45222,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; } @@ -44384,7 +45242,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"); @@ -44399,7 +45258,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; } @@ -44408,7 +45267,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); @@ -44422,13 +45281,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; } @@ -44441,21 +45303,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; @@ -44469,8 +45331,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[] = { @@ -44488,7 +45350,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, @@ -44519,9 +45381,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"); @@ -44532,15 +45394,15 @@ 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]; @@ -44552,8 +45414,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); } @@ -44570,7 +45432,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; } @@ -44579,7 +45441,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); @@ -44593,13 +45455,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; } @@ -44612,21 +45477,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; @@ -44640,8 +45505,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[] = { @@ -44654,7 +45519,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, @@ -44685,18 +45550,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; } @@ -44705,7 +45570,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"); @@ -44713,7 +45579,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; } @@ -44722,18 +45588,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; } @@ -44742,20 +45608,20 @@ 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]; @@ -44767,8 +45633,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); } @@ -44785,7 +45651,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; } @@ -44794,7 +45660,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"); @@ -44802,7 +45669,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; } @@ -44811,14 +45678,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"); @@ -44827,11 +45694,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"); @@ -44840,11 +45708,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"); @@ -44853,14 +45722,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"); @@ -44869,7 +45738,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); @@ -44883,13 +45752,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; } @@ -44902,21 +45774,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; @@ -44930,8 +45802,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[] = { @@ -44954,7 +45826,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, @@ -44985,18 +45857,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; } @@ -45005,13 +45877,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; } @@ -45020,25 +45893,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; } @@ -45047,25 +45920,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; } @@ -45074,9 +45947,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"); @@ -45086,33 +45959,33 @@ 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]; @@ -45124,8 +45997,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); } @@ -45142,7 +46015,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; } @@ -45151,25 +46024,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; } @@ -45178,7 +46051,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"); @@ -45193,7 +46067,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; } @@ -45202,7 +46076,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"); @@ -45217,7 +46092,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; } @@ -45226,7 +46101,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"); @@ -45241,7 +46117,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; } @@ -45250,13 +46126,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; } @@ -45265,7 +46142,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); @@ -45279,13 +46156,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; } @@ -45298,21 +46178,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; @@ -45326,8 +46206,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[] = { @@ -45349,7 +46229,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, @@ -45380,25 +46260,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; } @@ -45407,25 +46287,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; } @@ -45434,25 +46314,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; } @@ -45461,7 +46341,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"); @@ -45469,7 +46350,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; } @@ -45478,9 +46359,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"); @@ -45489,13 +46370,13 @@ 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]; @@ -45507,8 +46388,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); } @@ -45525,7 +46406,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; } @@ -45534,7 +46415,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); @@ -45548,13 +46429,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; } @@ -45567,21 +46451,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; @@ -45595,8 +46479,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[] = { @@ -45613,7 +46497,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, @@ -45644,18 +46528,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; } @@ -45664,18 +46548,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"); @@ -45684,7 +46568,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; } @@ -45693,7 +46577,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"); @@ -45701,7 +46586,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; } @@ -45710,25 +46595,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; } @@ -45737,7 +46622,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"); @@ -45752,7 +46638,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; } @@ -45761,18 +46647,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; } @@ -45781,7 +46667,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); @@ -45795,13 +46681,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; } @@ -45814,21 +46703,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; @@ -45842,8 +46731,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[] = { @@ -45861,7 +46750,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, @@ -45892,20 +46781,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; } @@ -45914,18 +46803,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; } @@ -45934,13 +46823,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; } @@ -45949,7 +46839,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"); @@ -45957,7 +46848,7 @@ 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; } @@ -45966,7 +46857,8 @@ bool js_cocos2dx_Menu_isEnabled(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Menu_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::Menu* cobj = (cocos2d::Menu *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Menu_init : Invalid Native Object"); @@ -45974,7 +46866,7 @@ bool js_cocos2dx_Menu_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; } @@ -45983,18 +46875,18 @@ bool js_cocos2dx_Menu_init(JSContext *cx, uint32_t argc, jsval *vp) } 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; } @@ -46003,18 +46895,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; } @@ -46023,13 +46915,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; } @@ -46038,7 +46931,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); @@ -46052,13 +46945,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; } @@ -46071,21 +46967,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; @@ -46099,8 +46995,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[] = { @@ -46120,7 +47016,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, @@ -46151,7 +47047,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"); @@ -46159,7 +47056,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; } @@ -46168,18 +47065,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; } @@ -46188,25 +47085,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; } @@ -46215,7 +47112,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"); @@ -46223,7 +47121,7 @@ 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; } @@ -46232,12 +47130,12 @@ bool js_cocos2dx_ClippingNode_getAlphaThreshold(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ClippingNode_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); cocos2d::ClippingNode* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); 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"); @@ -46245,9 +47143,9 @@ bool js_cocos2dx_ClippingNode_init(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"); @@ -46256,7 +47154,7 @@ bool js_cocos2dx_ClippingNode_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; } } while(0); @@ -46266,7 +47164,7 @@ bool js_cocos2dx_ClippingNode_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; } } while(0); @@ -46276,7 +47174,8 @@ bool js_cocos2dx_ClippingNode_init(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -46291,7 +47190,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; } @@ -46300,18 +47199,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; } @@ -46320,7 +47219,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"); @@ -46328,7 +47228,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; } @@ -46337,16 +47237,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"); @@ -46362,7 +47262,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); @@ -46379,7 +47279,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); @@ -46388,7 +47288,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); @@ -46402,13 +47302,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; } @@ -46419,7 +47322,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; @@ -46433,8 +47336,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[] = { @@ -46456,7 +47359,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, @@ -46487,13 +47390,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; } @@ -46502,25 +47406,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; } @@ -46529,7 +47433,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"); @@ -46544,7 +47449,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; } @@ -46553,18 +47458,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; } @@ -46573,18 +47478,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; } @@ -46593,18 +47498,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; } @@ -46613,7 +47518,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"); @@ -46621,7 +47527,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; } @@ -46630,7 +47536,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"); @@ -46638,7 +47545,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; } @@ -46647,7 +47554,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"); @@ -46655,7 +47563,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; } @@ -46664,34 +47572,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"); @@ -46700,7 +47608,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); @@ -46708,24 +47616,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); @@ -46735,18 +47643,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; } @@ -46755,28 +47663,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"); @@ -46792,7 +47700,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); @@ -46800,19 +47708,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; @@ -46824,7 +47732,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); @@ -46833,7 +47741,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); @@ -46847,13 +47755,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; } @@ -46866,21 +47777,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; @@ -46894,8 +47805,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[] = { @@ -46921,7 +47832,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, @@ -46952,18 +47863,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"); @@ -46972,7 +47883,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; } @@ -46981,7 +47892,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"); @@ -46989,7 +47901,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; } @@ -46998,18 +47910,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; } @@ -47018,7 +47930,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"); @@ -47026,7 +47939,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; } @@ -47035,25 +47948,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; } @@ -47062,7 +47975,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"); @@ -47070,7 +47984,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; } @@ -47079,7 +47993,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"); @@ -47094,7 +48009,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; } @@ -47103,18 +48018,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; } @@ -47123,7 +48038,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"); @@ -47131,7 +48047,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; } @@ -47140,21 +48056,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); @@ -47162,9 +48078,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); @@ -47174,7 +48090,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"); @@ -47182,7 +48099,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; } @@ -47191,18 +48108,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; } @@ -47211,18 +48128,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; } @@ -47231,14 +48148,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"); @@ -47254,7 +48171,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"); @@ -47263,7 +48180,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); @@ -47277,13 +48194,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; } @@ -47296,21 +48216,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; @@ -47324,8 +48244,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[] = { @@ -47353,7 +48273,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, @@ -47384,12 +48304,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"); @@ -47397,16 +48317,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); @@ -47414,10 +48334,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); @@ -47427,12 +48347,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"); @@ -47440,16 +48360,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); @@ -47457,10 +48377,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); @@ -47470,7 +48390,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"); @@ -47485,7 +48406,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; } @@ -47494,18 +48415,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; } @@ -47514,18 +48435,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; } @@ -47534,18 +48455,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; } @@ -47554,18 +48475,18 @@ 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; } @@ -47574,20 +48495,20 @@ bool js_cocos2dx_Sprite_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_initWithSpriteFrameName : 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_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; } @@ -47596,12 +48517,12 @@ bool js_cocos2dx_Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t argc, js } 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"); @@ -47609,21 +48530,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); @@ -47632,9 +48553,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"); @@ -47643,7 +48564,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); @@ -47652,23 +48573,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); @@ -47678,7 +48599,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"); @@ -47693,7 +48615,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; } @@ -47702,7 +48624,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"); @@ -47710,7 +48633,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; } @@ -47719,18 +48642,18 @@ 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; } @@ -47739,13 +48662,14 @@ bool js_cocos2dx_Sprite_removeAllChildrenWithCleanup(JSContext *cx, uint32_t arg } bool js_cocos2dx_Sprite_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::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); + args.rval().setUndefined(); return true; } @@ -47754,27 +48678,27 @@ bool js_cocos2dx_Sprite_updateTransform(JSContext *cx, uint32_t argc, jsval *vp) } 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); @@ -47782,10 +48706,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); @@ -47795,7 +48719,8 @@ bool js_cocos2dx_Sprite_setTextureRect(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Sprite_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::Sprite* cobj = (cocos2d::Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sprite_init : Invalid Native Object"); @@ -47803,7 +48728,7 @@ bool js_cocos2dx_Sprite_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; } @@ -47812,18 +48737,18 @@ bool js_cocos2dx_Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -47832,7 +48757,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; } @@ -47841,7 +48766,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"); @@ -47849,7 +48775,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; } @@ -47858,25 +48784,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; } @@ -47885,7 +48811,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"); @@ -47893,7 +48820,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; } @@ -47902,20 +48829,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; } @@ -47924,25 +48851,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; } @@ -47951,7 +48878,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"); @@ -47966,7 +48894,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; } @@ -47975,7 +48903,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"); @@ -47983,7 +48912,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; } @@ -47992,18 +48921,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; } @@ -48012,18 +48941,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; } @@ -48032,7 +48961,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"); @@ -48040,7 +48970,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; } @@ -48049,7 +48979,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"); @@ -48057,7 +48988,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; } @@ -48066,27 +48997,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); @@ -48094,12 +49025,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); @@ -48109,18 +49040,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; } @@ -48129,7 +49060,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"); @@ -48144,7 +49076,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; } @@ -48153,18 +49085,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"); @@ -48173,7 +49105,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; } @@ -48182,7 +49114,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"); @@ -48190,7 +49123,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; } @@ -48199,7 +49132,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"); @@ -48207,7 +49141,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; } @@ -48216,18 +49150,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; } @@ -48236,13 +49170,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; @@ -48254,7 +49188,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); @@ -48271,7 +49205,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); @@ -48279,10 +49213,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; @@ -48294,7 +49228,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); @@ -48303,23 +49237,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; @@ -48331,7 +49265,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); @@ -48339,19 +49273,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; @@ -48363,7 +49297,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); @@ -48372,9 +49306,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"); @@ -48390,7 +49324,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); @@ -48399,11 +49333,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; @@ -48415,7 +49349,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"); @@ -48424,14 +49358,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"); @@ -48447,7 +49381,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"); @@ -48456,7 +49390,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); @@ -48470,13 +49404,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; } @@ -48489,21 +49426,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; @@ -48517,8 +49454,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[] = { @@ -48570,7 +49507,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, @@ -48601,7 +49538,8 @@ JSObject *jsb_cocos2d_Image_prototype; bool js_cocos2dx_Image_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::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_hasPremultipliedAlpha : Invalid Native Object"); @@ -48609,7 +49547,7 @@ bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval 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; } @@ -48618,7 +49556,8 @@ bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48626,7 +49565,7 @@ bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp) ssize_t ret = cobj->getDataLen(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48635,32 +49574,32 @@ bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_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 = JS_THIS_OBJECT(cx, 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_saveToFile : 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_Image_saveToFile : Error processing arguments"); 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; } 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_Image_saveToFile : Error processing arguments"); 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; } @@ -48669,7 +49608,8 @@ bool js_cocos2dx_Image_saveToFile(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48677,7 +49617,7 @@ bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->hasAlpha(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48686,7 +49626,8 @@ bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48694,7 +49635,7 @@ bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->isCompressed(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48703,7 +49644,8 @@ bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_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::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getHeight : Invalid Native Object"); @@ -48711,7 +49653,7 @@ bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getHeight(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48720,20 +49662,20 @@ bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, 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_initWithImageFile : 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_Image_initWithImageFile : Error processing arguments"); bool ret = cobj->initWithImageFile(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48742,7 +49684,8 @@ bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Image_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::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_getWidth : Invalid Native Object"); @@ -48750,7 +49693,7 @@ bool js_cocos2dx_Image_getWidth(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getWidth(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48759,7 +49702,8 @@ bool js_cocos2dx_Image_getWidth(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48767,7 +49711,7 @@ bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp) int ret = cobj->getBitPerPixel(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48776,7 +49720,8 @@ bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_getFileType(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48784,7 +49729,7 @@ bool js_cocos2dx_Image_getFileType(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getFileType(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48793,7 +49738,8 @@ bool js_cocos2dx_Image_getFileType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_getNumberOfMipmaps(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48801,7 +49747,7 @@ bool js_cocos2dx_Image_getNumberOfMipmaps(JSContext *cx, uint32_t argc, jsval *v int ret = cobj->getNumberOfMipmaps(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48810,7 +49756,8 @@ bool js_cocos2dx_Image_getNumberOfMipmaps(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_Image_getRenderFormat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48818,7 +49765,7 @@ bool js_cocos2dx_Image_getRenderFormat(JSContext *cx, uint32_t argc, jsval *vp) int ret = (int)cobj->getRenderFormat(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48827,7 +49774,8 @@ bool js_cocos2dx_Image_getRenderFormat(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_getData(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48835,7 +49783,7 @@ bool js_cocos2dx_Image_getData(JSContext *cx, uint32_t argc, jsval *vp) unsigned char* ret = cobj->getData(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR unsigned char*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48844,7 +49792,8 @@ bool js_cocos2dx_Image_getData(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_getMipmaps(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -48852,7 +49801,7 @@ bool js_cocos2dx_Image_getMipmaps(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::_MipmapInfo* ret = cobj->getMipmaps(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR _MipmapInfo*; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48861,9 +49810,9 @@ bool js_cocos2dx_Image_getMipmaps(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, 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_initWithRawData : Invalid Native Object"); @@ -48875,15 +49824,15 @@ bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp) int arg4; #pragma warning NO CONVERSION TO NATIVE FOR unsigned char* ok = false; - ok &= jsval_to_ssize(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], (int32_t *)&arg4); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } if (argc == 6) { @@ -48895,16 +49844,16 @@ bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp) bool arg5; #pragma warning NO CONVERSION TO NATIVE FOR unsigned char* ok = false; - ok &= jsval_to_ssize(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], (int32_t *)&arg4); - arg5 = JS::ToBoolean(JS::RootedValue(cx, argv[5])); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -48913,14 +49862,14 @@ bool js_cocos2dx_Image_initWithRawData(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha(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_Image_setPVRImagesHavePremultipliedAlpha : Error processing arguments"); cocos2d::Image::setPVRImagesHavePremultipliedAlpha(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha : wrong number of arguments"); @@ -48929,7 +49878,7 @@ bool js_cocos2dx_Image_setPVRImagesHavePremultipliedAlpha(JSContext *cx, uint32_ bool js_cocos2dx_Image_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::Image* cobj = new (std::nothrow) cocos2d::Image(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -48943,13 +49892,16 @@ bool js_cocos2dx_Image_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::Image"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::Image"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -48959,7 +49911,7 @@ void js_cocos2d_Image_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Image)", obj); } -void js_register_cocos2dx_Image(JSContext *cx, JSObject *global) { +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; @@ -48973,8 +49925,8 @@ void js_register_cocos2dx_Image(JSContext *cx, JSObject *global) { jsb_cocos2d_Image_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -49003,7 +49955,7 @@ void js_register_cocos2dx_Image(JSContext *cx, JSObject *global) { jsb_cocos2d_Image_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_Image_class, js_cocos2dx_Image_constructor, 0, // constructor properties, @@ -49034,9 +49986,9 @@ 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"); @@ -49044,12 +49996,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; } @@ -49058,18 +50010,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; } @@ -49078,7 +50030,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"); @@ -49086,7 +50039,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; } @@ -49095,7 +50048,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"); @@ -49103,7 +50057,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; } @@ -49112,13 +50066,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; } @@ -49127,18 +50082,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; } @@ -49147,25 +50102,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; } @@ -49174,7 +50129,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"); @@ -49189,7 +50145,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; } @@ -49198,7 +50154,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"); @@ -49206,7 +50163,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; } @@ -49215,18 +50172,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; } @@ -49235,18 +50192,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; } @@ -49255,13 +50212,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; } @@ -49270,18 +50228,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; } @@ -49290,18 +50248,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; } @@ -49310,13 +50268,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; } @@ -49325,34 +50284,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); @@ -49360,19 +50319,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); @@ -49380,25 +50339,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); @@ -49408,18 +50367,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; } @@ -49428,7 +50387,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"); @@ -49436,7 +50396,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; } @@ -49445,9 +50405,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"); @@ -49456,13 +50416,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; } @@ -49471,7 +50431,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"); @@ -49479,7 +50440,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; } @@ -49488,9 +50449,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"); @@ -49505,12 +50466,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; @@ -49522,7 +50483,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; } @@ -49531,18 +50492,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; } @@ -49551,33 +50512,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); @@ -49585,18 +50546,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); @@ -49606,19 +50567,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; @@ -49630,7 +50591,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); @@ -49638,16 +50599,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; @@ -49659,7 +50620,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); @@ -49667,10 +50628,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; @@ -49682,7 +50643,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); @@ -49691,7 +50652,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); @@ -49705,13 +50666,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; } @@ -49724,21 +50688,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; @@ -49752,8 +50716,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[] = { @@ -49791,7 +50755,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, @@ -49822,25 +50786,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; } @@ -49849,12 +50813,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"); @@ -49870,7 +50834,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); @@ -49887,7 +50851,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); @@ -49897,6 +50861,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; @@ -49908,7 +50873,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"); @@ -49917,7 +50882,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); @@ -49931,13 +50896,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; } @@ -49948,7 +50916,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; @@ -49962,8 +50930,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[] = { @@ -49979,7 +50947,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, @@ -50010,25 +50978,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; } @@ -50037,9 +51005,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"); @@ -50047,19 +51015,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; } @@ -50068,18 +51036,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; } @@ -50088,7 +51056,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"); @@ -50103,7 +51072,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; } @@ -50112,25 +51081,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; } @@ -50139,22 +51108,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; } @@ -50163,18 +51132,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; } @@ -50183,18 +51152,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; } @@ -50203,7 +51172,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"); @@ -50218,7 +51188,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; } @@ -50227,7 +51197,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"); @@ -50235,7 +51206,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; } @@ -50244,9 +51215,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"); @@ -50254,17 +51225,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; } @@ -50273,20 +51244,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; } @@ -50295,11 +51266,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; @@ -50311,14 +51282,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; @@ -50330,7 +51301,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"); @@ -50339,14 +51310,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"); @@ -50362,21 +51333,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; @@ -50388,7 +51359,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"); @@ -50397,7 +51368,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); @@ -50411,13 +51382,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; } @@ -50430,21 +51404,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; @@ -50458,8 +51432,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[] = { @@ -50487,7 +51461,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, @@ -50518,7 +51492,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"); @@ -50526,7 +51501,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; } @@ -50535,7 +51510,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"); @@ -50550,7 +51526,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; } @@ -50559,7 +51535,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"); @@ -50567,7 +51544,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; } @@ -50576,7 +51553,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"); @@ -50591,7 +51569,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; } @@ -50600,7 +51578,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"); @@ -50608,7 +51587,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; } @@ -50617,7 +51596,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"); @@ -50625,7 +51605,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; } @@ -50634,18 +51614,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; } @@ -50654,7 +51634,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"); @@ -50662,7 +51643,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; } @@ -50671,18 +51652,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; } @@ -50691,7 +51672,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"); @@ -50699,7 +51681,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; } @@ -50708,7 +51690,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"); @@ -50716,7 +51699,7 @@ 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; } @@ -50725,7 +51708,8 @@ bool js_cocos2dx_ParticleSystem_getRadialAccelVar(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_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::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_init : Invalid Native Object"); @@ -50733,7 +51717,7 @@ bool js_cocos2dx_ParticleSystem_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; } @@ -50742,7 +51726,8 @@ bool js_cocos2dx_ParticleSystem_init(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -50750,7 +51735,7 @@ 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; } @@ -50759,18 +51744,18 @@ bool js_cocos2dx_ParticleSystem_getEndSizeVar(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ParticleSystem_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::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); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setRotation : Error processing arguments"); cobj->setRotation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50779,18 +51764,18 @@ bool js_cocos2dx_ParticleSystem_setRotation(JSContext *cx, uint32_t argc, jsval } 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; } @@ -50799,18 +51784,18 @@ bool js_cocos2dx_ParticleSystem_setTangentialAccel(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ParticleSystem_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::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); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScaleY : Error processing arguments"); cobj->setScaleY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50819,18 +51804,18 @@ bool js_cocos2dx_ParticleSystem_setScaleY(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ParticleSystem_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::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); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScaleX : Error processing arguments"); cobj->setScaleX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -50839,7 +51824,8 @@ bool js_cocos2dx_ParticleSystem_setScaleX(JSContext *cx, uint32_t argc, jsval *v } 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"); @@ -50847,7 +51833,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; } @@ -50856,18 +51842,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; } @@ -50876,18 +51862,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; } @@ -50896,18 +51882,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; } @@ -50916,7 +51902,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"); @@ -50924,7 +51911,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; } @@ -50933,7 +51920,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"); @@ -50941,7 +51929,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; } @@ -50950,18 +51938,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; } @@ -50970,7 +51958,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"); @@ -50978,7 +51967,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; } @@ -50987,7 +51976,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"); @@ -50995,7 +51985,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; } @@ -51004,18 +51994,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; } @@ -51024,18 +52014,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; } @@ -51044,18 +52034,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; } @@ -51064,20 +52054,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; } @@ -51086,25 +52076,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; } @@ -51113,7 +52103,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"); @@ -51121,7 +52112,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; } @@ -51130,13 +52121,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; } @@ -51145,7 +52137,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"); @@ -51153,7 +52146,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; } @@ -51162,7 +52155,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"); @@ -51170,7 +52164,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; } @@ -51179,18 +52173,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; } @@ -51199,13 +52193,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; } @@ -51214,7 +52209,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"); @@ -51222,7 +52218,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; } @@ -51231,18 +52227,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; } @@ -51251,18 +52247,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; } @@ -51271,18 +52267,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; } @@ -51291,9 +52287,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"); @@ -51302,10 +52298,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; } @@ -51314,7 +52310,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"); @@ -51322,7 +52319,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; } @@ -51331,7 +52328,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"); @@ -51339,7 +52337,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; } @@ -51348,18 +52346,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; } @@ -51368,13 +52366,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; } @@ -51383,18 +52382,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; } @@ -51403,18 +52402,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; } @@ -51423,18 +52422,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; } @@ -51443,7 +52442,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"); @@ -51451,7 +52451,7 @@ 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; } @@ -51460,7 +52460,8 @@ bool js_cocos2dx_ParticleSystem_getEndRadius(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ParticleSystem_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::ParticleSystem* cobj = (cocos2d::ParticleSystem *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ParticleSystem_isOpacityModifyRGB : Invalid Native Object"); @@ -51468,7 +52469,7 @@ bool js_cocos2dx_ParticleSystem_isOpacityModifyRGB(JSContext *cx, uint32_t argc, 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; } @@ -51477,7 +52478,8 @@ bool js_cocos2dx_ParticleSystem_isOpacityModifyRGB(JSContext *cx, uint32_t argc, } 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"); @@ -51485,7 +52487,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; } @@ -51494,18 +52496,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; } @@ -51514,18 +52516,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; } @@ -51534,18 +52536,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; } @@ -51554,7 +52556,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"); @@ -51562,7 +52565,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; } @@ -51571,7 +52574,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"); @@ -51579,7 +52583,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; } @@ -51588,9 +52592,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"); @@ -51600,7 +52604,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; } @@ -51609,18 +52613,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; } @@ -51629,7 +52633,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"); @@ -51637,7 +52642,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; } @@ -51646,18 +52651,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; } @@ -51666,7 +52671,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"); @@ -51674,7 +52680,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; } @@ -51683,18 +52689,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; } @@ -51703,18 +52709,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; } @@ -51723,18 +52729,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; } @@ -51743,18 +52749,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; } @@ -51763,18 +52769,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; } @@ -51783,18 +52789,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; } @@ -51803,25 +52809,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; } @@ -51830,7 +52836,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"); @@ -51838,7 +52845,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; } @@ -51847,7 +52854,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"); @@ -51855,7 +52863,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; } @@ -51864,18 +52872,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; } @@ -51884,20 +52892,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; } @@ -51906,7 +52914,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"); @@ -51914,7 +52923,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; } @@ -51923,18 +52932,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; } @@ -51943,7 +52952,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"); @@ -51951,7 +52961,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; } @@ -51960,7 +52970,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"); @@ -51968,7 +52979,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; } @@ -51977,7 +52988,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"); @@ -51985,7 +52997,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; } @@ -51994,18 +53006,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; } @@ -52014,18 +53026,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; } @@ -52034,18 +53046,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; } @@ -52054,13 +53066,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; } @@ -52069,18 +53082,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; } @@ -52089,7 +53102,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"); @@ -52097,7 +53111,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; } @@ -52106,7 +53120,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"); @@ -52114,7 +53129,7 @@ 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; } @@ -52123,18 +53138,18 @@ bool js_cocos2dx_ParticleSystem_getRotationIsDir(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ParticleSystem_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); 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); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setScale : Error processing arguments"); cobj->setScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -52143,7 +53158,8 @@ bool js_cocos2dx_ParticleSystem_setScale(JSContext *cx, uint32_t argc, jsval *vp } 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"); @@ -52151,7 +53167,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; } @@ -52160,7 +53176,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"); @@ -52168,7 +53185,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; } @@ -52177,7 +53194,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"); @@ -52185,7 +53203,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; } @@ -52194,18 +53212,18 @@ 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; } @@ -52214,18 +53232,18 @@ bool js_cocos2dx_ParticleSystem_setStartSizeVar(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ParticleSystem_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ParticleSystem_setOpacityModifyRGB : Error processing arguments"); cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -52234,7 +53252,8 @@ bool js_cocos2dx_ParticleSystem_setOpacityModifyRGB(JSContext *cx, uint32_t argc } 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"); @@ -52242,7 +53261,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; } @@ -52251,7 +53270,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"); @@ -52259,7 +53279,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; } @@ -52268,7 +53288,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"); @@ -52276,7 +53297,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; } @@ -52285,7 +53306,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"); @@ -52293,7 +53315,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; } @@ -52302,7 +53324,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"); @@ -52310,7 +53333,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; } @@ -52319,18 +53342,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; } @@ -52339,18 +53362,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; } @@ -52359,18 +53382,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; } @@ -52379,27 +53402,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); @@ -52407,12 +53430,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); @@ -52422,7 +53445,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"); @@ -52430,7 +53454,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; } @@ -52439,7 +53463,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"); @@ -52447,7 +53472,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; } @@ -52456,18 +53481,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; } @@ -52476,18 +53501,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; } @@ -52496,7 +53521,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"); @@ -52504,7 +53530,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; } @@ -52513,7 +53539,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"); @@ -52521,7 +53548,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; } @@ -52530,11 +53557,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; @@ -52546,7 +53573,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"); @@ -52555,11 +53582,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; @@ -52571,7 +53598,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"); @@ -52580,7 +53607,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); @@ -52594,13 +53621,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; } @@ -52613,21 +53643,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; @@ -52641,8 +53671,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[] = { @@ -52764,7 +53794,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, @@ -52795,25 +53825,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; } @@ -52822,9 +53852,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"); @@ -52832,17 +53862,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; } @@ -52851,25 +53881,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; } @@ -52878,13 +53908,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; @@ -52896,7 +53926,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); @@ -52913,7 +53943,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); @@ -52921,7 +53951,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; @@ -52933,7 +53963,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); @@ -52942,11 +53972,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; @@ -52958,7 +53988,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"); @@ -52967,7 +53997,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); @@ -52981,13 +54011,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; } @@ -52998,7 +54031,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; @@ -53012,8 +54045,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[] = { @@ -53031,7 +54064,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, @@ -53062,7 +54095,8 @@ 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::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); 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"); @@ -53070,7 +54104,7 @@ bool js_cocos2dx_ParticleFire_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; } @@ -53079,6 +54113,7 @@ bool js_cocos2dx_ParticleFire_init(JSContext *cx, uint32_t argc, jsval *vp) } 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; @@ -53090,7 +54125,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"); @@ -53099,11 +54134,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; @@ -53115,7 +54150,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"); @@ -53124,7 +54159,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); @@ -53138,13 +54173,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; } @@ -53155,7 +54193,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; @@ -53169,8 +54207,8 @@ 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[] = { @@ -53186,7 +54224,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, @@ -53217,7 +54255,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"); @@ -53225,7 +54264,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; } @@ -53234,20 +54273,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; } @@ -53256,6 +54295,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; @@ -53267,7 +54307,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"); @@ -53276,11 +54316,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; @@ -53292,7 +54332,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"); @@ -53301,7 +54341,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); @@ -53315,13 +54355,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; } @@ -53332,7 +54375,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; @@ -53346,8 +54389,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[] = { @@ -53364,7 +54407,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, @@ -53395,7 +54438,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"); @@ -53403,7 +54447,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; } @@ -53412,20 +54456,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; } @@ -53434,6 +54478,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; @@ -53445,7 +54490,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"); @@ -53454,11 +54499,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; @@ -53470,7 +54515,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"); @@ -53479,7 +54524,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); @@ -53493,13 +54538,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; } @@ -53510,7 +54558,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; @@ -53524,8 +54572,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[] = { @@ -53542,7 +54590,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, @@ -53573,7 +54621,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"); @@ -53581,7 +54630,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; } @@ -53590,20 +54639,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; } @@ -53612,6 +54661,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; @@ -53623,7 +54673,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"); @@ -53632,11 +54682,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; @@ -53648,7 +54698,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"); @@ -53657,7 +54707,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); @@ -53671,13 +54721,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; } @@ -53688,7 +54741,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; @@ -53702,8 +54755,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[] = { @@ -53720,7 +54773,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, @@ -53751,7 +54804,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"); @@ -53759,7 +54813,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; } @@ -53768,20 +54822,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; } @@ -53790,6 +54844,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; @@ -53801,7 +54856,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"); @@ -53810,11 +54865,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; @@ -53826,7 +54881,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"); @@ -53835,7 +54890,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); @@ -53849,13 +54904,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; } @@ -53866,7 +54924,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; @@ -53880,8 +54938,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[] = { @@ -53898,7 +54956,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, @@ -53929,7 +54987,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"); @@ -53937,7 +54996,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; } @@ -53946,20 +55005,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; } @@ -53968,6 +55027,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; @@ -53979,7 +55039,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"); @@ -53988,11 +55048,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; @@ -54004,7 +55064,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"); @@ -54013,7 +55073,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); @@ -54027,13 +55087,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; } @@ -54044,7 +55107,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; @@ -54058,8 +55121,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[] = { @@ -54076,7 +55139,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, @@ -54107,7 +55170,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"); @@ -54115,7 +55179,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; } @@ -54124,20 +55188,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; } @@ -54146,6 +55210,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; @@ -54157,7 +55222,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"); @@ -54166,11 +55231,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; @@ -54182,7 +55247,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"); @@ -54191,7 +55256,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); @@ -54205,13 +55270,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; } @@ -54222,7 +55290,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; @@ -54236,8 +55304,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[] = { @@ -54254,7 +55322,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, @@ -54285,7 +55353,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"); @@ -54293,7 +55362,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; } @@ -54302,20 +55371,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; } @@ -54324,6 +55393,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; @@ -54335,7 +55405,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"); @@ -54344,11 +55414,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; @@ -54360,7 +55430,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"); @@ -54369,7 +55439,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); @@ -54383,13 +55453,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; } @@ -54400,7 +55473,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; @@ -54414,8 +55487,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[] = { @@ -54432,7 +55505,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, @@ -54463,7 +55536,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"); @@ -54471,7 +55545,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; } @@ -54480,20 +55554,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; } @@ -54502,6 +55576,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; @@ -54513,7 +55588,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"); @@ -54522,11 +55597,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; @@ -54538,7 +55613,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"); @@ -54547,7 +55622,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); @@ -54561,13 +55636,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; } @@ -54578,7 +55656,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; @@ -54592,8 +55670,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[] = { @@ -54610,7 +55688,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, @@ -54641,7 +55719,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"); @@ -54649,7 +55728,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; } @@ -54658,20 +55737,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; } @@ -54680,6 +55759,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; @@ -54691,7 +55771,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"); @@ -54700,11 +55780,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; @@ -54716,7 +55796,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"); @@ -54725,7 +55805,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); @@ -54739,13 +55819,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; } @@ -54756,7 +55839,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; @@ -54770,8 +55853,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[] = { @@ -54788,7 +55871,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, @@ -54819,7 +55902,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"); @@ -54827,7 +55911,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; } @@ -54836,20 +55920,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; } @@ -54858,6 +55942,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; @@ -54869,7 +55954,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"); @@ -54878,11 +55963,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; @@ -54894,7 +55979,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"); @@ -54903,7 +55988,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); @@ -54917,13 +56002,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; } @@ -54934,7 +56022,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; @@ -54948,8 +56036,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[] = { @@ -54966,7 +56054,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, @@ -54997,18 +56085,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; } @@ -55017,13 +56105,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; } @@ -55032,25 +56121,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; } @@ -55059,13 +56148,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; } @@ -55074,13 +56164,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; } @@ -55089,7 +56180,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"); @@ -55097,7 +56189,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; } @@ -55106,7 +56198,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"); @@ -55114,7 +56207,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; } @@ -55123,7 +56216,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"); @@ -55131,7 +56225,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; } @@ -55140,13 +56234,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; } @@ -55155,18 +56250,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; } @@ -55175,18 +56270,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; } @@ -55195,13 +56290,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; } @@ -55210,18 +56306,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; } @@ -55230,7 +56326,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"); @@ -55238,7 +56335,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; } @@ -55247,24 +56344,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); @@ -55272,24 +56369,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); @@ -55299,13 +56396,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; } @@ -55314,18 +56412,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; } @@ -55334,7 +56432,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"); @@ -55342,7 +56441,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; } @@ -55351,13 +56450,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; } @@ -55366,13 +56466,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; @@ -55384,7 +56484,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); @@ -55392,20 +56492,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; @@ -55417,7 +56517,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); @@ -55432,21 +56532,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; @@ -55460,8 +56560,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[] = { @@ -55495,7 +56595,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, @@ -55526,7 +56626,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"); @@ -55534,7 +56635,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; } @@ -55543,18 +56644,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; } @@ -55563,13 +56664,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; @@ -55581,7 +56682,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); @@ -55589,20 +56690,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; @@ -55614,7 +56715,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); @@ -55623,7 +56724,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); @@ -55637,13 +56738,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; } @@ -55656,21 +56760,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; @@ -55684,8 +56788,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[] = { @@ -55702,7 +56806,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, @@ -55733,13 +56837,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; @@ -55751,7 +56855,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); @@ -55759,20 +56863,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; @@ -55784,7 +56888,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); @@ -55793,7 +56897,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); @@ -55807,13 +56911,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; } @@ -55826,21 +56933,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; @@ -55854,8 +56961,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[] = { @@ -55870,7 +56977,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, @@ -55901,25 +57008,25 @@ 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; } @@ -55928,7 +57035,8 @@ bool js_cocos2dx_Camera_setScene(JSContext *cx, uint32_t argc, jsval *vp) } 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"); @@ -55936,7 +57044,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; } @@ -55945,7 +57053,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"); @@ -55953,7 +57062,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; } @@ -55962,7 +57071,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"); @@ -55970,7 +57080,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; } @@ -55979,7 +57089,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"); @@ -55987,7 +57098,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; } @@ -55996,7 +57107,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"); @@ -56004,7 +57116,7 @@ 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; } @@ -56013,20 +57125,20 @@ bool js_cocos2dx_Camera_getType(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Camera_getDepthInView(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_getDepthInView : 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_Camera_getDepthInView : Error processing arguments"); double ret = cobj->getDepthInView(arg0); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56035,77 +57147,48 @@ bool js_cocos2dx_Camera_getDepthInView(JSContext *cx, uint32_t argc, jsval *vp) } 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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + 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, 1); return false; } -bool js_cocos2dx_Camera_isVisibleInFrustum(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::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_isVisibleInFrustum : Invalid Native Object"); - if (argc == 1) { - const cocos2d::AABB* 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 = (const cocos2d::AABB*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_isVisibleInFrustum : Error processing arguments"); - bool ret = cobj->isVisibleInFrustum(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, 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_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; } @@ -56114,9 +57197,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"); @@ -56125,15 +57208,15 @@ 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; } @@ -56142,9 +57225,9 @@ bool js_cocos2dx_Camera_initOrthographic(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); @@ -56153,15 +57236,15 @@ bool js_cocos2dx_Camera_initPerspective(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_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); + args.rval().set(jsret); return true; } @@ -56170,7 +57253,8 @@ bool js_cocos2dx_Camera_initPerspective(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -56178,7 +57262,7 @@ bool js_cocos2dx_Camera_initDefault(JSContext *cx, uint32_t argc, jsval *vp) bool ret = cobj->initDefault(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -56187,18 +57271,18 @@ bool js_cocos2dx_Camera_initDefault(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_setAdditionalProjection : 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_Camera_setAdditionalProjection : Error processing arguments"); cobj->setAdditionalProjection(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -56207,6 +57291,7 @@ bool js_cocos2dx_Camera_setAdditionalProjection(JSContext *cx, uint32_t argc, js } 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; @@ -56218,7 +57303,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"); @@ -56227,17 +57312,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; @@ -56249,7 +57334,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"); @@ -56258,17 +57343,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; @@ -56280,7 +57365,7 @@ 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"); @@ -56289,6 +57374,7 @@ bool js_cocos2dx_Camera_createOrthographic(JSContext *cx, uint32_t argc, jsval * 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; @@ -56300,7 +57386,7 @@ bool js_cocos2dx_Camera_getDefaultCamera(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_getDefaultCamera : wrong number of arguments"); @@ -56309,6 +57395,7 @@ bool js_cocos2dx_Camera_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp 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; @@ -56320,7 +57407,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"); @@ -56329,7 +57416,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); @@ -56343,13 +57430,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; } @@ -56360,7 +57450,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; @@ -56374,8 +57464,8 @@ 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[] = { @@ -56387,7 +57477,6 @@ void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { JS_FN("getType", js_cocos2dx_Camera_getType, 0, 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("isVisibleInFrustum", js_cocos2dx_Camera_isVisibleInFrustum, 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), @@ -56407,7 +57496,7 @@ void js_register_cocos2dx_Camera(JSContext *cx, JSObject *global) { 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, @@ -56433,12 +57522,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"); @@ -56446,7 +58545,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; } @@ -56455,20 +58554,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; } @@ -56477,20 +58576,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; } @@ -56499,13 +58598,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; } @@ -56514,7 +58614,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"); @@ -56522,7 +58623,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; } @@ -56531,20 +58632,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; } @@ -56553,22 +58654,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; } @@ -56577,20 +58678,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; } @@ -56599,22 +58700,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; } @@ -56623,9 +58724,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"); @@ -56634,13 +58735,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; } @@ -56649,22 +58750,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); @@ -56672,7 +58773,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); @@ -56682,9 +58783,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"); @@ -56693,13 +58794,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; } @@ -56708,9 +58809,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"); @@ -56720,14 +58821,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; } @@ -56736,13 +58837,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; } @@ -56751,20 +58853,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; } @@ -56773,7 +58875,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"); @@ -56781,7 +58884,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; } @@ -56790,13 +58893,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; } @@ -56805,20 +58909,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; } @@ -56827,20 +58931,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; } @@ -56849,9 +58953,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"); @@ -56859,12 +58963,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; } @@ -56873,9 +58977,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"); @@ -56885,14 +58989,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; } @@ -56901,20 +59005,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; } @@ -56923,9 +59027,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"); @@ -56933,12 +59037,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; } @@ -56947,13 +59051,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; @@ -56965,7 +59069,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"); @@ -56974,13 +59078,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; @@ -56992,7 +59096,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"); @@ -57001,7 +59105,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); @@ -57015,13 +59119,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; } @@ -57033,21 +59140,21 @@ void js_cocos2d_GLProgram_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_GLProgram_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::GLProgram *nobj = new (std::nothrow) cocos2d::GLProgram(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLProgram"); + 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", 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_GLProgram(JSContext *cx, JSObject *global) { +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; @@ -57061,8 +59168,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[] = { @@ -57101,7 +59208,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, @@ -57132,13 +59239,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; } @@ -57147,9 +59255,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"); @@ -57157,17 +59265,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; } @@ -57176,15 +59284,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; @@ -57196,7 +59304,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; } @@ -57205,13 +59313,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; } @@ -57220,9 +59329,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"); @@ -57231,6 +59341,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; @@ -57242,7 +59353,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"); @@ -57251,7 +59362,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); @@ -57265,13 +59376,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; } @@ -57281,7 +59395,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; @@ -57295,8 +59409,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[] = { @@ -57315,7 +59429,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, @@ -57346,20 +59460,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; } @@ -57368,13 +59482,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; } @@ -57383,18 +59498,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; } @@ -57403,13 +59518,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; } @@ -57418,20 +59534,20 @@ 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]; @@ -57443,8 +59559,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); } @@ -57459,7 +59575,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; } @@ -57468,7 +59584,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"); @@ -57476,7 +59593,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; } @@ -57485,7 +59602,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"); @@ -57493,7 +59611,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; } @@ -57502,12 +59620,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"); @@ -57515,16 +59633,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; @@ -57536,7 +59654,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); @@ -57544,7 +59662,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; @@ -57556,7 +59674,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); @@ -57566,18 +59684,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; } @@ -57586,15 +59704,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; @@ -57606,7 +59724,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; } @@ -57615,13 +59733,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; } @@ -57630,25 +59749,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; } @@ -57657,13 +59776,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; } @@ -57672,7 +59792,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); @@ -57686,13 +59806,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; } @@ -57702,7 +59825,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; @@ -57716,8 +59839,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[] = { @@ -57741,7 +59864,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, @@ -57772,14 +59895,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"); @@ -57788,14 +59911,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"); @@ -57804,14 +59927,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"); @@ -57820,11 +59943,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"); @@ -57837,7 +59961,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; @@ -57851,8 +59975,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[] = { @@ -57869,7 +59993,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, @@ -57900,20 +60024,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; } @@ -57926,7 +60050,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; @@ -57940,8 +60064,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[] = { @@ -57953,7 +60077,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, @@ -57984,20 +60108,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; } @@ -58006,7 +60130,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"); @@ -58014,7 +60139,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; } @@ -58023,7 +60148,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"); @@ -58031,7 +60157,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; } @@ -58040,6 +60166,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; @@ -58051,7 +60178,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"); @@ -58064,7 +60191,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; @@ -58078,8 +60205,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[] = { @@ -58096,7 +60223,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, @@ -58127,15 +60254,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; @@ -58147,7 +60274,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; } @@ -58156,9 +60283,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"); @@ -58166,17 +60293,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; } @@ -58185,7 +60312,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"); @@ -58193,7 +60321,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; } @@ -58202,20 +60330,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; } @@ -58224,18 +60352,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; } @@ -58244,18 +60372,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; } @@ -58264,9 +60392,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"); @@ -58275,6 +60404,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; @@ -58286,7 +60416,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"); @@ -58295,7 +60425,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); @@ -58309,13 +60439,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; } @@ -58325,7 +60458,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; @@ -58339,8 +60472,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[] = { @@ -58361,7 +60494,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, @@ -58392,27 +60525,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; } @@ -58421,25 +60554,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); @@ -58447,10 +60580,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); @@ -58458,20 +60591,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); @@ -58481,9 +60614,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"); @@ -58491,17 +60624,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; } @@ -58510,13 +60643,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; } @@ -58525,15 +60659,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; @@ -58545,7 +60679,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; } @@ -58554,18 +60688,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; } @@ -58574,7 +60708,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"); @@ -58582,7 +60717,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; } @@ -58591,13 +60726,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; } @@ -58606,25 +60742,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; } @@ -58633,18 +60769,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; } @@ -58653,18 +60789,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; } @@ -58673,9 +60809,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"); @@ -58684,6 +60821,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; @@ -58695,7 +60833,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"); @@ -58708,7 +60846,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; @@ -58722,8 +60860,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[] = { @@ -58749,7 +60887,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, @@ -58780,7 +60918,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"); @@ -58788,7 +60927,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; } @@ -58797,18 +60936,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; } @@ -58817,7 +60956,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"); @@ -58825,7 +60965,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; } @@ -58834,30 +60974,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); @@ -58865,24 +61005,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); @@ -58892,22 +61032,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); @@ -58915,10 +61055,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); @@ -58928,7 +61068,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"); @@ -58936,7 +61077,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; } @@ -58945,18 +61086,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; } @@ -58965,7 +61106,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"); @@ -58973,7 +61115,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; } @@ -58982,7 +61124,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"); @@ -58990,7 +61133,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; } @@ -58999,7 +61142,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"); @@ -59007,7 +61151,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; } @@ -59016,19 +61160,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; @@ -59040,7 +61184,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); @@ -59048,19 +61192,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; @@ -59072,7 +61216,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); @@ -59081,7 +61225,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); @@ -59095,13 +61239,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; } @@ -59114,21 +61261,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; @@ -59142,8 +61289,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[] = { @@ -59168,7 +61315,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, @@ -59199,12 +61346,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"); @@ -59213,7 +61360,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); @@ -59223,7 +61370,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); @@ -59233,9 +61380,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"); @@ -59245,19 +61392,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; } @@ -59266,18 +61413,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; } @@ -59286,9 +61433,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"); @@ -59298,7 +61445,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; } @@ -59307,6 +61454,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; @@ -59318,7 +61466,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"); @@ -59327,7 +61475,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); @@ -59341,13 +61489,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; } @@ -59360,21 +61511,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; @@ -59388,8 +61539,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[] = { @@ -59408,7 +61559,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, @@ -59439,18 +61590,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; } @@ -59459,20 +61610,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; } @@ -59481,7 +61632,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"); @@ -59489,7 +61641,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; } @@ -59498,20 +61650,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; } @@ -59520,12 +61672,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"); @@ -59534,7 +61686,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); @@ -59544,7 +61696,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); @@ -59554,18 +61706,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; } @@ -59574,12 +61726,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"); @@ -59588,7 +61740,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); @@ -59598,7 +61750,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); @@ -59608,7 +61760,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"); @@ -59616,7 +61769,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; } @@ -59625,18 +61778,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; } @@ -59645,18 +61798,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; } @@ -59665,7 +61818,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); @@ -59679,13 +61832,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; } @@ -59695,7 +61851,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; @@ -59709,8 +61865,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[] = { @@ -59731,7 +61887,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, @@ -59762,18 +61918,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; } @@ -59782,7 +61938,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"); @@ -59790,7 +61947,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; } @@ -59799,7 +61956,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); @@ -59813,13 +61970,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; } @@ -59829,7 +61989,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; @@ -59843,8 +62003,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[] = { @@ -59857,7 +62017,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, @@ -59888,20 +62048,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; } @@ -59910,7 +62070,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); @@ -59924,13 +62084,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; } @@ -59940,7 +62103,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; @@ -59954,8 +62117,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[] = { @@ -59967,7 +62130,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, @@ -59998,18 +62161,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; } @@ -60018,18 +62181,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; } @@ -60038,20 +62201,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; } @@ -60060,7 +62223,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"); @@ -60068,7 +62232,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; } @@ -60077,7 +62241,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"); @@ -60085,7 +62250,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; } @@ -60094,18 +62259,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; } @@ -60114,20 +62279,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; } @@ -60136,7 +62301,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"); @@ -60144,7 +62310,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; } @@ -60153,18 +62319,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; } @@ -60173,20 +62339,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; } @@ -60195,12 +62361,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"); @@ -60209,7 +62375,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); @@ -60219,7 +62385,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); @@ -60229,12 +62395,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"); @@ -60243,7 +62409,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); @@ -60253,7 +62419,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); @@ -60263,7 +62429,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"); @@ -60271,7 +62438,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; } @@ -60280,18 +62447,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; } @@ -60300,22 +62467,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; } @@ -60324,18 +62491,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; } @@ -60344,7 +62511,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"); @@ -60352,7 +62520,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; } @@ -60361,7 +62529,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"); @@ -60369,7 +62538,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; } @@ -60378,7 +62547,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"); @@ -60386,7 +62556,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; } @@ -60395,12 +62565,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"); @@ -60409,7 +62579,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); @@ -60419,7 +62589,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); @@ -60429,7 +62599,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"); @@ -60437,7 +62608,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; } @@ -60446,18 +62617,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; } @@ -60466,18 +62637,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; } @@ -60486,18 +62657,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; } @@ -60506,18 +62677,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; } @@ -60526,18 +62697,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; } @@ -60546,18 +62717,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; } @@ -60566,7 +62737,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"); @@ -60574,7 +62746,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; } @@ -60583,18 +62755,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; } @@ -60603,12 +62775,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"); @@ -60617,7 +62789,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); @@ -60627,7 +62799,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); @@ -60637,7 +62809,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"); @@ -60645,7 +62818,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; } @@ -60654,18 +62827,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; } @@ -60674,11 +62847,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; @@ -60690,7 +62863,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"); @@ -60699,13 +62872,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; @@ -60717,7 +62890,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"); @@ -60726,7 +62899,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); @@ -60740,13 +62913,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; } @@ -60758,21 +62934,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; @@ -60786,8 +62962,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[] = { @@ -60835,7 +63011,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, @@ -60866,33 +63042,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; } @@ -60901,20 +63077,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; } @@ -60923,18 +63099,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; } @@ -60943,13 +63119,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; } @@ -60958,9 +63135,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"); @@ -60970,7 +63147,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; } @@ -60979,7 +63156,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"); @@ -60987,7 +63165,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; } @@ -60996,18 +63174,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; } @@ -61016,7 +63194,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"); @@ -61024,7 +63203,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; } @@ -61033,18 +63212,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; } @@ -61053,18 +63232,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; } @@ -61073,18 +63252,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; } @@ -61093,9 +63272,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"); @@ -61104,25 +63283,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"); @@ -61131,7 +63310,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; } @@ -61140,13 +63319,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; } @@ -61155,28 +63335,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); @@ -61184,13 +63364,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); @@ -61200,7 +63380,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"); @@ -61208,7 +63389,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; } @@ -61217,20 +63398,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; } @@ -61239,18 +63420,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; } @@ -61259,7 +63440,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"); @@ -61267,7 +63449,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; } @@ -61276,25 +63458,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; } @@ -61303,7 +63485,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"); @@ -61318,7 +63501,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; } @@ -61327,12 +63510,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"); @@ -61341,7 +63524,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); @@ -61351,7 +63534,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); @@ -61361,15 +63544,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; @@ -61381,7 +63564,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; } @@ -61390,32 +63573,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"); @@ -61431,7 +63614,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"); @@ -61440,7 +63623,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); @@ -61454,13 +63637,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; } @@ -61473,21 +63659,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; @@ -61501,8 +63687,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[] = { @@ -61539,7 +63725,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, @@ -61570,18 +63756,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; } @@ -61590,20 +63776,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; } @@ -61612,18 +63798,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; } @@ -61632,15 +63818,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; @@ -61652,7 +63838,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; } @@ -61661,12 +63847,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"); @@ -61675,7 +63861,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); @@ -61685,7 +63871,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); @@ -61695,22 +63881,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; } @@ -61719,20 +63905,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; } @@ -61741,7 +63927,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"); @@ -61749,7 +63936,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; } @@ -61758,7 +63945,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"); @@ -61766,7 +63954,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; } @@ -61775,7 +63963,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"); @@ -61783,7 +63972,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; } @@ -61792,25 +63981,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"); @@ -61819,7 +64008,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); @@ -61827,12 +64016,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); @@ -61842,18 +64031,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; } @@ -61862,18 +64051,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; } @@ -61882,15 +64071,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; @@ -61902,7 +64091,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; } @@ -61911,7 +64100,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"); @@ -61919,7 +64109,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; } @@ -61928,18 +64118,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; } @@ -61948,11 +64138,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; @@ -61964,7 +64154,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"); @@ -61973,13 +64163,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; @@ -61991,7 +64181,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"); @@ -62000,7 +64190,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); @@ -62014,13 +64204,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; } @@ -62033,21 +64226,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; @@ -62061,8 +64254,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[] = { @@ -62094,7 +64287,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, @@ -62125,9 +64318,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"); @@ -62136,15 +64329,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; } @@ -62153,13 +64346,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; } @@ -62168,7 +64362,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"); @@ -62176,7 +64371,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; } @@ -62185,20 +64380,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; } @@ -62207,20 +64402,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; } @@ -62229,9 +64424,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"); @@ -62241,7 +64436,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; } @@ -62250,17 +64445,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; @@ -62272,7 +64467,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"); @@ -62281,7 +64476,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); @@ -62295,13 +64490,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; } @@ -62314,21 +64512,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; @@ -62342,8 +64540,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[] = { @@ -62364,7 +64562,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, @@ -62395,18 +64593,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; } @@ -62415,18 +64613,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; } @@ -62435,7 +64633,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"); @@ -62443,7 +64642,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; } @@ -62452,18 +64651,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; } @@ -62472,7 +64671,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"); @@ -62487,7 +64687,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; } @@ -62496,7 +64696,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"); @@ -62504,7 +64705,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; } @@ -62513,25 +64714,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; } @@ -62540,7 +64741,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"); @@ -62548,7 +64750,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; } @@ -62557,6 +64759,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; @@ -62568,7 +64771,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"); @@ -62577,7 +64780,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); @@ -62591,13 +64794,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; } @@ -62609,21 +64815,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; @@ -62637,8 +64843,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[] = { @@ -62661,7 +64867,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, @@ -62692,18 +64898,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; } @@ -62712,12 +64918,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"); @@ -62725,9 +64931,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"); @@ -62736,7 +64942,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); @@ -62744,12 +64950,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); @@ -62759,13 +64965,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; } @@ -62774,18 +64981,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"); @@ -62794,7 +65001,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; } @@ -62803,7 +65010,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"); @@ -62811,7 +65019,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; } @@ -62820,15 +65028,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; @@ -62840,7 +65048,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; } @@ -62853,7 +65061,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; @@ -62867,8 +65075,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[] = { @@ -62885,7 +65093,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, @@ -62916,18 +65124,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; } @@ -62936,23 +65144,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; } @@ -62961,13 +65169,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; } @@ -62976,7 +65185,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"); @@ -62984,7 +65194,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; } @@ -62993,13 +65203,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; } @@ -63008,18 +65219,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; } @@ -63028,18 +65239,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; } @@ -63048,7 +65259,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"); @@ -63056,7 +65268,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; } @@ -63065,7 +65277,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"); @@ -63073,7 +65286,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; } @@ -63082,7 +65295,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"); @@ -63090,7 +65304,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; } @@ -63099,18 +65313,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; } @@ -63119,46 +65333,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) { @@ -63166,15 +65380,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) { @@ -63183,16 +65397,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; } @@ -63201,13 +65415,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; } @@ -63216,28 +65431,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; } @@ -63246,13 +65461,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; } @@ -63261,18 +65477,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; } @@ -63281,18 +65497,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; } @@ -63301,13 +65517,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; } @@ -63316,13 +65533,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; } @@ -63331,18 +65549,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; } @@ -63351,18 +65569,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; } @@ -63371,9 +65589,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"); @@ -63382,6 +65601,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; @@ -63393,7 +65613,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"); @@ -63406,7 +65626,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; @@ -63420,8 +65640,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[] = { @@ -63457,7 +65677,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, @@ -63483,267 +65703,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_EaseRateAction(cx, obj); - js_register_cocos2dx_EaseOut(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_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_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_Image(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_EaseBezierAction(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 ab6151cf9b..9e1fb006b3 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,8 +109,8 @@ 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); @@ -120,8 +120,8 @@ 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); @@ -150,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); @@ -166,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); @@ -187,6 +187,7 @@ 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); @@ -194,6 +195,7 @@ 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_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); @@ -207,24 +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); @@ -235,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); @@ -253,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); @@ -270,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; @@ -279,8 +280,8 @@ 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_render(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval *vp); @@ -298,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); @@ -335,8 +336,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); @@ -407,8 +408,8 @@ 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_performFunctionInCocosThread(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scheduler_getTimeScale(JSContext *cx, uint32_t argc, jsval *vp); @@ -419,8 +420,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); @@ -457,8 +458,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); @@ -469,8 +470,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); @@ -491,8 +492,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); @@ -503,8 +504,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); @@ -513,8 +514,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); @@ -523,8 +524,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); @@ -547,8 +548,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); @@ -557,8 +558,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; @@ -566,8 +567,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); @@ -577,8 +578,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); @@ -587,8 +588,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); @@ -597,8 +598,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; @@ -606,8 +607,8 @@ 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_EventListenerFocus(JSContext *cx, uint32_t argc, jsval *vp); @@ -616,8 +617,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); @@ -637,8 +638,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); @@ -647,8 +648,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); @@ -662,8 +663,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); @@ -675,8 +676,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); @@ -705,8 +706,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); @@ -723,8 +724,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); @@ -751,8 +752,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); @@ -763,8 +764,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); @@ -773,8 +774,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); @@ -786,8 +787,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); @@ -799,8 +800,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); @@ -809,8 +810,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); @@ -820,8 +821,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); @@ -831,8 +832,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); @@ -842,8 +843,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); @@ -853,8 +854,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); @@ -864,8 +865,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); @@ -875,8 +876,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); @@ -886,8 +887,8 @@ 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); @@ -897,8 +898,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; @@ -906,8 +907,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; @@ -915,8 +916,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); @@ -926,8 +927,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); @@ -936,8 +937,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); @@ -947,8 +948,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); @@ -958,8 +959,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); @@ -969,8 +970,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); @@ -980,8 +981,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); @@ -991,8 +992,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); @@ -1002,8 +1003,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); @@ -1012,8 +1013,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); @@ -1023,8 +1024,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); @@ -1036,8 +1037,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); @@ -1049,8 +1050,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); @@ -1064,8 +1065,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); @@ -1076,8 +1077,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); @@ -1098,8 +1099,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); @@ -1108,8 +1109,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); @@ -1119,8 +1120,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); @@ -1129,8 +1130,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); @@ -1139,8 +1140,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); @@ -1149,8 +1150,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); @@ -1159,8 +1160,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); @@ -1169,8 +1170,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); @@ -1179,8 +1180,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); @@ -1189,8 +1190,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); @@ -1199,8 +1200,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); @@ -1209,8 +1210,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); @@ -1220,8 +1221,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); @@ -1230,8 +1231,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); @@ -1240,8 +1241,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); @@ -1250,16 +1251,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); @@ -1268,8 +1269,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); @@ -1278,8 +1279,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); @@ -1288,8 +1289,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); @@ -1298,8 +1299,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); @@ -1308,8 +1309,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); @@ -1318,8 +1319,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); @@ -1329,8 +1330,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); @@ -1339,8 +1340,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); @@ -1349,8 +1350,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); @@ -1359,8 +1360,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); @@ -1369,8 +1370,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); @@ -1379,8 +1380,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); @@ -1389,8 +1390,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); @@ -1399,8 +1400,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); @@ -1409,8 +1410,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); @@ -1419,8 +1420,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); @@ -1429,8 +1430,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); @@ -1439,8 +1440,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); @@ -1449,8 +1450,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); @@ -1459,8 +1460,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); @@ -1469,8 +1470,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); @@ -1479,16 +1480,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); @@ -1497,8 +1498,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); @@ -1507,8 +1508,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); @@ -1517,8 +1518,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); @@ -1528,8 +1529,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); @@ -1539,8 +1540,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); @@ -1550,8 +1551,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); @@ -1561,8 +1562,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); @@ -1571,8 +1572,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; @@ -1580,8 +1581,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); @@ -1590,8 +1591,8 @@ 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); +void js_register_cocos2dx_Grid3DAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Grid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_TiledGrid3DAction_class; @@ -1599,8 +1600,8 @@ 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); +void js_register_cocos2dx_TiledGrid3DAction(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TiledGrid3DAction_getGrid(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_StopGrid_class; @@ -1608,8 +1609,8 @@ 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); @@ -1618,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); @@ -1629,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); @@ -1644,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); @@ -1656,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); @@ -1666,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); @@ -1682,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); @@ -1699,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); @@ -1710,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); @@ -1725,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); @@ -1740,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); @@ -1757,8 +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); +void js_register_cocos2dx_PageTurn3D(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_PageTurn3D_getGrid(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_PageTurn3D_create(JSContext *cx, uint32_t argc, jsval *vp); @@ -1767,8 +1768,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); @@ -1778,8 +1779,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); @@ -1789,8 +1790,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); @@ -1800,8 +1801,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); @@ -1811,8 +1812,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); @@ -1825,8 +1826,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); @@ -1839,8 +1840,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); @@ -1849,8 +1850,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); +void js_register_cocos2dx_FadeOutUpTiles(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_FadeOutUpTiles_transformTile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutUpTiles_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FadeOutUpTiles_FadeOutUpTiles(JSContext *cx, uint32_t argc, jsval *vp); @@ -1860,8 +1861,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); @@ -1870,8 +1871,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); @@ -1884,8 +1885,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); @@ -1899,8 +1900,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); @@ -1914,8 +1915,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); @@ -1925,8 +1926,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); @@ -1936,8 +1937,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); @@ -1946,8 +1947,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); @@ -1957,8 +1958,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; @@ -1966,24 +1967,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); @@ -2002,8 +2003,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); @@ -2020,7 +2021,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); @@ -2031,8 +2031,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); @@ -2052,8 +2052,8 @@ 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); @@ -2085,8 +2085,8 @@ 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); @@ -2099,8 +2099,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); @@ -2135,8 +2135,8 @@ 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); @@ -2166,8 +2166,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); @@ -2221,8 +2221,8 @@ 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); @@ -2244,8 +2244,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); @@ -2254,8 +2254,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); @@ -2264,8 +2264,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); @@ -2280,8 +2280,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); @@ -2304,8 +2304,8 @@ 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); @@ -2318,8 +2318,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; @@ -2327,8 +2327,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); @@ -2340,8 +2340,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); @@ -2351,8 +2351,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); @@ -2361,8 +2361,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); @@ -2371,8 +2371,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); @@ -2383,8 +2383,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); @@ -2393,8 +2393,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); @@ -2403,8 +2403,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); @@ -2413,8 +2413,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); @@ -2425,8 +2425,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); +void js_register_cocos2dx_TransitionSlideInR(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInR_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInR_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInR_TransitionSlideInR(JSContext *cx, uint32_t argc, jsval *vp); @@ -2436,8 +2436,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); +void js_register_cocos2dx_TransitionSlideInB(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInB_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInB_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInB_TransitionSlideInB(JSContext *cx, uint32_t argc, jsval *vp); @@ -2447,8 +2447,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); +void js_register_cocos2dx_TransitionSlideInT(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_TransitionSlideInT_action(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInT_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TransitionSlideInT_TransitionSlideInT(JSContext *cx, uint32_t argc, jsval *vp); @@ -2458,8 +2458,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); @@ -2469,8 +2469,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); @@ -2479,8 +2479,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); @@ -2489,8 +2489,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); @@ -2499,8 +2499,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); @@ -2509,8 +2509,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); @@ -2519,8 +2519,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); @@ -2529,8 +2529,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); @@ -2540,8 +2540,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); @@ -2550,8 +2550,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); @@ -2561,8 +2561,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); @@ -2573,8 +2573,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); @@ -2583,8 +2583,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); @@ -2595,8 +2595,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); @@ -2605,8 +2605,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); @@ -2615,8 +2615,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); @@ -2625,8 +2625,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); @@ -2637,8 +2637,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); @@ -2647,8 +2647,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); @@ -2657,8 +2657,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); @@ -2667,8 +2667,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); @@ -2677,8 +2677,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); @@ -2687,8 +2687,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); @@ -2697,8 +2697,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); @@ -2707,8 +2707,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); @@ -2724,8 +2724,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); @@ -2739,8 +2739,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); @@ -2749,8 +2749,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); @@ -2767,8 +2767,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); @@ -2786,8 +2786,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); @@ -2800,8 +2800,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); @@ -2815,8 +2815,8 @@ 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); @@ -2832,8 +2832,8 @@ 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); @@ -2850,8 +2850,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); @@ -2871,8 +2871,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); @@ -2894,8 +2894,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); @@ -2941,8 +2941,8 @@ 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, JSObject *global); -void register_all_cocos2dx(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); @@ -2966,8 +2966,8 @@ 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); @@ -2999,8 +2999,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); @@ -3011,8 +3011,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); @@ -3034,8 +3034,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); @@ -3151,8 +3151,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); @@ -3165,8 +3165,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); +void js_register_cocos2dx_ParticleFire(JSContext *cx, JS::HandleObject global); +void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ParticleFire_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFire_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ParticleFire_createWithTotalParticles(JSContext *cx, uint32_t argc, jsval *vp); @@ -3177,8 +3177,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); @@ -3190,8 +3190,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); @@ -3203,8 +3203,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); @@ -3216,8 +3216,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); @@ -3229,8 +3229,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); @@ -3242,8 +3242,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); @@ -3255,8 +3255,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); @@ -3268,8 +3268,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); @@ -3281,8 +3281,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); @@ -3294,8 +3294,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); @@ -3307,8 +3307,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); @@ -3335,8 +3335,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); @@ -3347,8 +3347,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); @@ -3357,8 +3357,8 @@ 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_getProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_getViewProjectionMatrix(JSContext *cx, uint32_t argc, jsval *vp); @@ -3367,7 +3367,6 @@ 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_getDepthInView(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Camera_lookAt(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Camera_isVisibleInFrustum(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); @@ -3380,13 +3379,84 @@ 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); @@ -3419,8 +3489,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); @@ -3434,8 +3504,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); @@ -3456,8 +3526,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); @@ -3468,8 +3538,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; @@ -3477,8 +3547,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); @@ -3489,8 +3559,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); @@ -3506,8 +3576,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); @@ -3527,8 +3597,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); @@ -3547,8 +3617,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); @@ -3561,8 +3631,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); @@ -3580,8 +3650,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); @@ -3591,8 +3661,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); @@ -3601,8 +3671,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); @@ -3644,8 +3714,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); @@ -3676,8 +3746,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); @@ -3703,8 +3773,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); @@ -3719,8 +3789,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); @@ -3737,8 +3807,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); @@ -3751,8 +3821,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); @@ -3776,5 +3846,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 e98da640b5..c02a139e3b 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,7 +426,7 @@ 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; } @@ -419,18 +435,18 @@ bool js_cocos2dx_extension_ControlButton_isPushed(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlButton_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setSelected : Error processing arguments"); cobj->setSelected(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -439,9 +455,9 @@ bool js_cocos2dx_extension_ControlButton_setSelected(JSContext *cx, uint32_t arg } 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 +465,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,18 +484,18 @@ 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; } @@ -488,18 +504,18 @@ bool js_cocos2dx_extension_ControlButton_setAdjustBackgroundImage(JSContext *cx, } bool js_cocos2dx_extension_ControlButton_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlButton_setHighlighted : Error processing arguments"); cobj->setHighlighted(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -508,18 +524,18 @@ bool js_cocos2dx_extension_ControlButton_setHighlighted(JSContext *cx, uint32_t } 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_setZoomOnTouchDown : 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_setZoomOnTouchDown : Error processing arguments"); cobj->setZoomOnTouchDown(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -528,20 +544,20 @@ bool js_cocos2dx_extension_ControlButton_setZoomOnTouchDown(JSContext *cx, uint3 } 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 +566,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 +586,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 +595,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 +604,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 +624,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 +633,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 +655,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 +677,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 +699,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 +726,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 +746,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,7 +755,7 @@ 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; } @@ -746,18 +764,18 @@ bool js_cocos2dx_extension_ControlButton_getCurrentTitleColor(JSContext *cx, uin } bool js_cocos2dx_extension_ControlButton_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::ControlButton* cobj = (cocos2d::extension::ControlButton *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlButton_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_ControlButton_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -766,25 +784,25 @@ bool js_cocos2dx_extension_ControlButton_setEnabled(JSContext *cx, uint32_t argc } 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 +811,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 +831,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 +840,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,7 +849,7 @@ 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; } @@ -839,13 +858,14 @@ bool js_cocos2dx_extension_ControlButton_getHorizontalOrigin(JSContext *cx, uint } bool js_cocos2dx_extension_ControlButton_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::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); + args.rval().setUndefined(); return true; } @@ -854,9 +874,9 @@ bool js_cocos2dx_extension_ControlButton_needsLayout(JSContext *cx, uint32_t arg } 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,14 +884,14 @@ 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; } @@ -880,12 +900,12 @@ bool js_cocos2dx_extension_ControlButton_initWithTitleAndFontNameAndFontSize(JSC } 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 = NULL; + JS::RootedObject obj(cx); cocos2d::extension::ControlButton* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = 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"); @@ -894,7 +914,7 @@ bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t std::string ret = cobj->getCurrentTitle(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -904,7 +924,7 @@ bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t const std::string& ret = cobj->getCurrentTitle(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -914,7 +934,8 @@ bool js_cocos2dx_extension_ControlButton_getCurrentTitle(JSContext *cx, uint32_t } 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 +943,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 +952,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 +974,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 +990,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 +999,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 +1021,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 +1043,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 +1052,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 +1061,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 +1071,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 +1090,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 +1100,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,18 +1119,18 @@ 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; } @@ -1116,9 +1139,9 @@ bool js_cocos2dx_extension_ControlButton_setScaleRatio(JSContext *cx, uint32_t a } 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_initWithLabelAndBackgroundSprite : Invalid Native Object"); @@ -1126,17 +1149,17 @@ bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSCont cocos2d::Node* arg0; cocos2d::ui::Scale9Sprite* 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::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); @@ -1145,7 +1168,7 @@ bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSCont bool ret = cobj->initWithLabelAndBackgroundSprite(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1154,7 +1177,8 @@ bool js_cocos2dx_extension_ControlButton_initWithLabelAndBackgroundSprite(JSCont } 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 +1193,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 +1202,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 +1211,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 +1220,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 +1229,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 +1238,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 +1258,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,20 +1267,20 @@ 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; } @@ -1263,20 +1289,20 @@ bool js_cocos2dx_extension_ControlButton_setMargins(JSContext *cx, uint32_t argc } 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 = 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_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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1285,20 +1311,20 @@ bool js_cocos2dx_extension_ControlButton_setTitleBMFontForState(JSContext *cx, u } 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_getTitleBMFontForState : 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_getTitleBMFontForState : Error processing arguments"); const std::string& ret = cobj->getTitleBMFontForState(arg0); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1307,7 +1333,8 @@ bool js_cocos2dx_extension_ControlButton_getTitleBMFontForState(JSContext *cx, u } 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 +1342,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 +1351,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 +1373,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 +1398,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 +1415,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 +1424,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 +1434,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 +1452,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 +1460,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 +1478,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 +1487,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 +1501,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 +1523,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,8 +1551,8 @@ 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[] = { @@ -1579,7 +1609,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, @@ -1610,18 +1640,18 @@ 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); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_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_ControlHuePicker_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1630,9 +1660,9 @@ bool js_cocos2dx_extension_ControlHuePicker_setEnabled(JSContext *cx, uint32_t a } 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 +1670,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 +1691,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 +1711,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 +1720,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 +1729,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 +1738,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 +1747,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 +1763,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 +1772,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 +1799,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 +1819,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 +1835,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 +1844,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 +1853,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 +1862,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 +1889,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 +1914,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 +1923,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 +1937,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 +1957,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,8 +1971,8 @@ 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[] = { @@ -1959,7 +1997,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 +2028,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 +2044,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 +2053,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 +2063,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 +2084,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 +2093,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 +2102,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,7 +2118,7 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay(JSContex jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2086,18 +2127,18 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_getOverlay(JSContex } bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2106,7 +2147,8 @@ bool js_cocos2dx_extension_ControlSaturationBrightnessPicker_setEnabled(JSContex } 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 +2163,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 +2172,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 +2188,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 +2197,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 +2206,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 +2215,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 +2224,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 +2233,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 +2258,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 +2267,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 +2281,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 +2301,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 +2315,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[] = { @@ -2291,7 +2339,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, @@ -2322,18 +2370,18 @@ JSObject *jsb_cocos2d_extension_ControlColourPicker_prototype; bool js_cocos2dx_extension_ControlColourPicker_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlColourPicker_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2342,7 +2390,8 @@ bool js_cocos2dx_extension_ControlColourPicker_setEnabled(JSContext *cx, uint32_ } 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,7 +2406,7 @@ 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; } @@ -2366,18 +2415,18 @@ bool js_cocos2dx_extension_ControlColourPicker_getHuePicker(JSContext *cx, uint3 } bool js_cocos2dx_extension_ControlColourPicker_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); 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); + ok &= jsval_to_cccolor3b(cx, args.get(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); + args.rval().setUndefined(); return true; } @@ -2386,9 +2435,9 @@ bool js_cocos2dx_extension_ControlColourPicker_setColor(JSContext *cx, uint32_t } 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_hueSliderValueChanged : Invalid Native Object"); @@ -2396,17 +2445,17 @@ bool js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged(JSContext * 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_hueSliderValueChanged : Error processing arguments"); cobj->hueSliderValueChanged(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -2415,7 +2464,8 @@ bool js_cocos2dx_extension_ControlColourPicker_hueSliderValueChanged(JSContext * } bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getcolourPicker : Invalid Native Object"); @@ -2430,7 +2480,7 @@ bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, ui jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -2439,25 +2489,25 @@ bool js_cocos2dx_extension_ControlColourPicker_getcolourPicker(JSContext *cx, ui } 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::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 +2516,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 +2543,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 +2553,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 +2572,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 +2599,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 +2615,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 +2624,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 +2636,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 +2645,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 +2659,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 +2681,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,8 +2709,8 @@ 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[] = { @@ -2680,7 +2735,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 +2766,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 +2786,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 +2806,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 +2822,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 +2831,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 +2840,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 +2849,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 +2860,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 +2877,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 +2897,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 +2917,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 +2926,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 +2935,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 +2962,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 +2971,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 +2980,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 +2989,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 +2998,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 +3022,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 +3042,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 +3069,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 +3089,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 +3105,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 +3114,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 +3125,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 +3152,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 +3161,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 +3181,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 +3201,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 +3210,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 +3224,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 +3246,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 +3274,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 +3308,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, @@ -3275,7 +3339,8 @@ JSObject *jsb_cocos2d_extension_ControlSlider_prototype; bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -3290,7 +3355,7 @@ bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, u jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3299,18 +3364,18 @@ bool js_cocos2dx_extension_ControlSlider_getSelectedThumbSprite(JSContext *cx, u } 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_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"); @@ -3319,7 +3384,7 @@ bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32 cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3328,25 +3393,25 @@ bool js_cocos2dx_extension_ControlSlider_locationFromTouch(JSContext *cx, uint32 } 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_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_setSelectedThumbSprite : Error processing arguments"); cobj->setSelectedThumbSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3355,25 +3420,25 @@ bool js_cocos2dx_extension_ControlSlider_setSelectedThumbSprite(JSContext *cx, u } 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; } @@ -3382,7 +3447,8 @@ bool js_cocos2dx_extension_ControlSlider_setProgressSprite(JSContext *cx, uint32 } bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getMaximumAllowedValue : Invalid Native Object"); @@ -3390,7 +3456,7 @@ bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, u double ret = cobj->getMaximumAllowedValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3399,7 +3465,8 @@ bool js_cocos2dx_extension_ControlSlider_getMaximumAllowedValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getMinimumAllowedValue : Invalid Native Object"); @@ -3407,7 +3474,7 @@ bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, u double ret = cobj->getMinimumAllowedValue(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3416,7 +3483,8 @@ bool js_cocos2dx_extension_ControlSlider_getMinimumAllowedValue(JSContext *cx, u } 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 +3492,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,25 +3501,25 @@ 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; } @@ -3460,18 +3528,18 @@ bool js_cocos2dx_extension_ControlSlider_setThumbSprite(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3480,18 +3548,18 @@ bool js_cocos2dx_extension_ControlSlider_setMinimumValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setMinimumAllowedValue : 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_setMinimumAllowedValue : Error processing arguments"); cobj->setMinimumAllowedValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3500,18 +3568,18 @@ bool js_cocos2dx_extension_ControlSlider_setMinimumAllowedValue(JSContext *cx, u } bool js_cocos2dx_extension_ControlSlider_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSlider_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3520,18 +3588,18 @@ bool js_cocos2dx_extension_ControlSlider_setEnabled(JSContext *cx, uint32_t argc } bool js_cocos2dx_extension_ControlSlider_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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3540,18 +3608,18 @@ bool js_cocos2dx_extension_ControlSlider_setValue(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlSlider_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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3560,13 +3628,14 @@ bool js_cocos2dx_extension_ControlSlider_setMaximumValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_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::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_needsLayout : Invalid Native Object"); if (argc == 0) { cobj->needsLayout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -3575,7 +3644,8 @@ bool js_cocos2dx_extension_ControlSlider_needsLayout(JSContext *cx, uint32_t arg } 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,7 +3660,7 @@ 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; } @@ -3599,12 +3669,12 @@ bool js_cocos2dx_extension_ControlSlider_getBackgroundSprite(JSContext *cx, uint } 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 = NULL; + JS::RootedObject obj(cx); cocos2d::extension::ControlSlider* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -3612,9 +3682,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3622,9 +3692,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3632,9 +3702,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3642,9 +3712,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3653,7 +3723,7 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t bool ret = cobj->initWithSprites(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); @@ -3662,9 +3732,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3672,9 +3742,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3682,9 +3752,9 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t 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"); @@ -3693,7 +3763,7 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t bool ret = cobj->initWithSprites(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); @@ -3703,7 +3773,8 @@ bool js_cocos2dx_extension_ControlSlider_initWithSprites(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_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::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getMaximumValue : Invalid Native Object"); @@ -3711,7 +3782,7 @@ bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t 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; } @@ -3720,18 +3791,18 @@ bool js_cocos2dx_extension_ControlSlider_getMaximumValue(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlSlider_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::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_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"); @@ -3740,7 +3811,7 @@ bool js_cocos2dx_extension_ControlSlider_isTouchInside(JSContext *cx, uint32_t a 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; } @@ -3749,7 +3820,8 @@ bool js_cocos2dx_extension_ControlSlider_isTouchInside(JSContext *cx, uint32_t a } 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_getValue : Invalid Native Object"); @@ -3757,7 +3829,7 @@ bool js_cocos2dx_extension_ControlSlider_getValue(JSContext *cx, uint32_t argc, 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; } @@ -3766,7 +3838,8 @@ bool js_cocos2dx_extension_ControlSlider_getValue(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlSlider_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::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_getThumbSprite : Invalid Native Object"); @@ -3781,7 +3854,7 @@ bool js_cocos2dx_extension_ControlSlider_getThumbSprite(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3790,7 +3863,8 @@ bool js_cocos2dx_extension_ControlSlider_getThumbSprite(JSContext *cx, uint32_t } 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,7 +3879,7 @@ 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; } @@ -3814,25 +3888,25 @@ bool js_cocos2dx_extension_ControlSlider_getProgressSprite(JSContext *cx, uint32 } bool js_cocos2dx_extension_ControlSlider_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::ControlSlider* cobj = (cocos2d::extension::ControlSlider *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlSlider_setBackgroundSprite : 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); + args.rval().setUndefined(); return true; } @@ -3841,18 +3915,18 @@ bool js_cocos2dx_extension_ControlSlider_setBackgroundSprite(JSContext *cx, uint } 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 +3935,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 +3952,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 +3962,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 +3980,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 +3988,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 +4006,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 +4014,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 +4035,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 +4044,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 +4054,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 +4064,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 +4074,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 +4092,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 +4101,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 +4115,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 +4137,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,8 +4165,8 @@ 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[] = { @@ -4127,7 +4204,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, @@ -4158,25 +4235,25 @@ 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); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setMinusSprite : 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_ControlStepper_setMinusSprite : Error processing arguments"); cobj->setMinusSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4185,7 +4262,8 @@ bool js_cocos2dx_extension_ControlStepper_setMinusSprite(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -4200,7 +4278,7 @@ bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4209,18 +4287,18 @@ bool js_cocos2dx_extension_ControlStepper_getMinusLabel(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_ControlStepper_setWraps : Error processing arguments"); cobj->setWraps(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4229,7 +4307,8 @@ bool js_cocos2dx_extension_ControlStepper_setWraps(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_isContinuous : Invalid Native Object"); @@ -4237,7 +4316,7 @@ bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t a bool ret = cobj->isContinuous(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4246,7 +4325,8 @@ bool js_cocos2dx_extension_ControlStepper_isContinuous(JSContext *cx, uint32_t a } 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_getMinusSprite : Invalid Native Object"); @@ -4261,7 +4341,7 @@ bool js_cocos2dx_extension_ControlStepper_getMinusSprite(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4270,18 +4350,18 @@ bool js_cocos2dx_extension_ControlStepper_getMinusSprite(JSContext *cx, uint32_t } 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_updateLayoutUsingTouchLocation : 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_ControlStepper_updateLayoutUsingTouchLocation : Error processing arguments"); cobj->updateLayoutUsingTouchLocation(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4290,20 +4370,20 @@ bool js_cocos2dx_extension_ControlStepper_updateLayoutUsingTouchLocation(JSConte } 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_setValueWithSendingEvent : 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_extension_ControlStepper_setValueWithSendingEvent : Error processing arguments"); cobj->setValueWithSendingEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4312,7 +4392,8 @@ bool js_cocos2dx_extension_ControlStepper_setValueWithSendingEvent(JSContext *cx } 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,7 +4408,7 @@ 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; } @@ -4336,13 +4417,14 @@ bool js_cocos2dx_extension_ControlStepper_getPlusLabel(JSContext *cx, uint32_t a } bool js_cocos2dx_extension_ControlStepper_stopAutorepeat(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_stopAutorepeat : Invalid Native Object"); if (argc == 0) { cobj->stopAutorepeat(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4351,18 +4433,18 @@ bool js_cocos2dx_extension_ControlStepper_stopAutorepeat(JSContext *cx, uint32_t } 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_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_ControlStepper_setMinimumValue : Error processing arguments"); cobj->setMinimumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4371,7 +4453,8 @@ bool js_cocos2dx_extension_ControlStepper_setMinimumValue(JSContext *cx, uint32_ } 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_getPlusSprite : Invalid Native Object"); @@ -4386,7 +4469,7 @@ bool js_cocos2dx_extension_ControlStepper_getPlusSprite(JSContext *cx, uint32_t jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4395,25 +4478,25 @@ bool js_cocos2dx_extension_ControlStepper_getPlusSprite(JSContext *cx, uint32_t } 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_setPlusSprite : 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_ControlStepper_setPlusSprite : Error processing arguments"); cobj->setPlusSprite(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4422,25 +4505,25 @@ bool js_cocos2dx_extension_ControlStepper_setPlusSprite(JSContext *cx, uint32_t } 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_setMinusLabel : Invalid Native Object"); if (argc == 1) { cocos2d::Label* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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); 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); + args.rval().setUndefined(); return true; } @@ -4449,18 +4532,18 @@ bool js_cocos2dx_extension_ControlStepper_setMinusLabel(JSContext *cx, uint32_t } 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_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_ControlStepper_setValue : Error processing arguments"); cobj->setValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4469,18 +4552,18 @@ bool js_cocos2dx_extension_ControlStepper_setValue(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_ControlStepper_setStepValue : Error processing arguments"); cobj->setStepValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4489,18 +4572,18 @@ bool js_cocos2dx_extension_ControlStepper_setStepValue(JSContext *cx, uint32_t a } 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_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_ControlStepper_setMaximumValue : Error processing arguments"); cobj->setMaximumValue(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4509,18 +4592,18 @@ bool js_cocos2dx_extension_ControlStepper_setMaximumValue(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlStepper_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::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); + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlStepper_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4529,13 +4612,14 @@ bool js_cocos2dx_extension_ControlStepper_update(JSContext *cx, uint32_t argc, j } 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_startAutorepeat : Invalid Native Object"); if (argc == 0) { cobj->startAutorepeat(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4544,9 +4628,9 @@ bool js_cocos2dx_extension_ControlStepper_startAutorepeat(JSContext *cx, uint32_ } bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); @@ -4554,17 +4638,17 @@ bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSCon 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"); @@ -4573,7 +4657,7 @@ bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSCon bool ret = cobj->initWithMinusSpriteAndPlusSprite(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4582,7 +4666,8 @@ bool js_cocos2dx_extension_ControlStepper_initWithMinusSpriteAndPlusSprite(JSCon } bool js_cocos2dx_extension_ControlStepper_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::ControlStepper* cobj = (cocos2d::extension::ControlStepper *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ControlStepper_getValue : Invalid Native Object"); @@ -4590,7 +4675,7 @@ bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, 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; } @@ -4599,25 +4684,25 @@ bool js_cocos2dx_extension_ControlStepper_getValue(JSContext *cx, uint32_t argc, } 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_setPlusLabel : Invalid Native Object"); if (argc == 1) { cocos2d::Label* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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); 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); + args.rval().setUndefined(); return true; } @@ -4626,23 +4711,23 @@ bool js_cocos2dx_extension_ControlStepper_setPlusLabel(JSContext *cx, uint32_t a } 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 +4743,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 +4752,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 +4766,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 +4788,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,8 +4816,8 @@ 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[] = { @@ -4765,7 +4853,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, @@ -4796,18 +4884,18 @@ 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); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_extension_ControlSwitch_setEnabled : Error processing arguments"); cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4816,21 +4904,21 @@ bool js_cocos2dx_extension_ControlSwitch_setEnabled(JSContext *cx, uint32_t argc } 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 +4926,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); @@ -4852,7 +4940,8 @@ bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsv } 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 +4949,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 +4958,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 +4971,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 +4981,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 +4991,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 +5001,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 +5011,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 +5021,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 +5032,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 +5041,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 +5051,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 +5061,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 +5071,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 +5082,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 +5092,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,7 +5101,7 @@ 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; } @@ -5020,18 +5110,18 @@ bool js_cocos2dx_extension_ControlSwitch_hasMoved(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ControlSwitch_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::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; } + if (!args.get(0).isObject()) { ok = false; break; } js_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"); @@ -5040,7 +5130,7 @@ bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32 cocos2d::Vec2 ret = cobj->locationFromTouch(arg0); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5049,16 +5139,16 @@ bool js_cocos2dx_extension_ControlSwitch_locationFromTouch(JSContext *cx, uint32 } 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 +5156,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 +5166,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 +5176,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 +5194,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 +5203,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 +5213,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 +5223,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 +5233,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 +5243,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 +5253,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 +5271,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 +5280,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 +5294,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 +5316,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,8 +5344,8 @@ 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[] = { @@ -5273,7 +5366,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 +5397,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 +5406,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 +5415,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 +5442,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 +5464,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 +5486,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 +5508,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 +5528,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 +5537,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 +5546,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 +5555,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 +5564,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 +5580,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 +5589,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 +5609,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 +5618,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 +5627,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 +5643,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 +5675,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 +5684,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,18 +5711,18 @@ 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; } @@ -5632,7 +5731,8 @@ bool js_cocos2dx_extension_ScrollView_setDirection(JSContext *cx, uint32_t argc, } bool js_cocos2dx_extension_ScrollView_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::extension::ScrollView* cobj = (cocos2d::extension::ScrollView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_extension_ScrollView_init : Invalid Native Object"); @@ -5640,7 +5740,7 @@ bool js_cocos2dx_extension_ScrollView_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; } @@ -5649,28 +5749,28 @@ bool js_cocos2dx_extension_ScrollView_init(JSContext *cx, uint32_t argc, jsval * } 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 +5779,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 +5788,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 +5797,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 +5806,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 +5815,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 +5824,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 +5833,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 +5853,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 +5862,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 +5871,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 +5898,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 +5918,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 +5938,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 +5947,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 +5956,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,7 +5965,7 @@ 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; } @@ -5868,18 +5974,18 @@ bool js_cocos2dx_extension_ScrollView_maxContainerOffset(JSContext *cx, uint32_t } bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setBounceable : 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_setBounceable : Error processing arguments"); cobj->setBounceable(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5888,7 +5994,8 @@ bool js_cocos2dx_extension_ScrollView_setBounceable(JSContext *cx, uint32_t argc } 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 +6003,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 +6012,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 +6032,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 +6041,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 +6050,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 +6059,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 +6084,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 +6097,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 +6112,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 +6120,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 +6132,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 +6161,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 +6170,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 +6184,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 +6206,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 +6234,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[] = { @@ -6171,7 +6282,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 +6313,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 +6329,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 +6338,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 +6347,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 +6367,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 +6379,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 +6388,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 +6402,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 +6424,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 +6452,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 +6471,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 +6502,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 +6522,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 +6542,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 +6569,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 +6585,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 +6594,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 +6603,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 +6623,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 +6655,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 +6664,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 +6691,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 +6707,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 +6727,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 +6747,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 +6756,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 +6772,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 +6781,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 +6795,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 +6817,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 +6845,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 +6870,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 +6901,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 +6917,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 +6926,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 +6935,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 +6944,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 +6953,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 +6962,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 +6971,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 +6980,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 +6989,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 +6998,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 +7007,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 +7016,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 +7025,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 +7034,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 +7043,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 +7052,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 +7080,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 +7100,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 +7114,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 +7134,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 +7165,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 +7174,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 +7183,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 +7192,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 +7201,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 +7210,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 +7219,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 +7228,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 +7237,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 +7246,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 +7255,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 +7264,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 +7273,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 +7282,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 +7295,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 +7309,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 +7328,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 +7359,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 +7368,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 +7377,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 +7393,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 +7402,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 +7411,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 +7427,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 +7443,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 +7452,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 +7468,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 +7477,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 +7493,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 +7511,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 +7520,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 +7539,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 +7558,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 +7572,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 +7594,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 +7625,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,17 +7635,17 @@ 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]; @@ -7505,8 +7657,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); } @@ -7523,7 +7675,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; } @@ -7532,23 +7684,23 @@ 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]; @@ -7560,8 +7712,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); } @@ -7585,7 +7737,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"); @@ -7594,7 +7746,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); @@ -7608,13 +7760,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; } @@ -7625,7 +7780,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; @@ -7639,8 +7794,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[] = { @@ -7655,7 +7810,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, @@ -7681,35 +7836,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..44c515c3a0 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,8 +32,8 @@ 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); @@ -84,8 +84,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); +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_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); 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); @@ -105,8 +105,8 @@ 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); @@ -124,8 +124,8 @@ 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); +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_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); @@ -144,8 +144,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,8 +172,8 @@ 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); +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_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); @@ -205,8 +205,8 @@ 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); +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_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); @@ -236,8 +236,8 @@ 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); +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_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_setOn(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_extension_ControlSwitch_isOn(JSContext *cx, uint32_t argc, jsval *vp); @@ -252,8 +252,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); @@ -294,8 +294,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 +307,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 +328,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 +345,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 +360,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 +377,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 55a819d891..954d50b0f3 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_spine_auto.cpp @@ -5,10 +5,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; @@ -19,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; } @@ -32,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; @@ -42,18 +47,18 @@ 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; } @@ -62,7 +67,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_setTimeScale(JSContext *cx, uint32_t arg } 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_getDebugSlotsEnabled : Invalid Native Object"); @@ -70,7 +76,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint 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; } @@ -79,22 +85,22 @@ bool js_cocos2dx_spine_SkeletonRenderer_getDebugSlotsEnabled(JSContext *cx, uint } 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_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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -103,13 +109,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t ar } bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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_setBonesToSetupPose : Invalid Native Object"); if (argc == 0) { cobj->setBonesToSetupPose(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -118,7 +125,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_setBonesToSetupPose(JSContext *cx, uint3 } 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_isOpacityModifyRGB : Invalid Native Object"); @@ -126,7 +134,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32 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; } @@ -135,9 +143,9 @@ bool js_cocos2dx_spine_SkeletonRenderer_isOpacityModifyRGB(JSContext *cx, uint32 } bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_initWithData : Invalid Native Object"); @@ -147,7 +155,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t arg ok = false; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithData : Error processing arguments"); cobj->initWithData(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { @@ -155,10 +163,10 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t arg bool arg1; #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* ok = false; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_spine_SkeletonRenderer_initWithData : Error processing arguments"); cobj->initWithData(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -167,18 +175,18 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithData(JSContext *cx, uint32_t arg } bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setDebugSlotsEnabled : 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_setDebugSlotsEnabled : Error processing arguments"); cobj->setDebugSlotsEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -187,13 +195,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_setDebugSlotsEnabled(JSContext *cx, uint } 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; } @@ -202,18 +211,18 @@ bool js_cocos2dx_spine_SkeletonRenderer_setSlotsToSetupPose(JSContext *cx, uint3 } 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_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_spine_SkeletonRenderer_setOpacityModifyRGB : Error processing arguments"); cobj->setOpacityModifyRGB(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -222,13 +231,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_setOpacityModifyRGB(JSContext *cx, uint3 } 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_setToSetupPose : Invalid Native Object"); if (argc == 0) { cobj->setToSetupPose(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -237,7 +247,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_setToSetupPose(JSContext *cx, uint32_t a } bool js_cocos2dx_spine_SkeletonRenderer_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); spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_spine_SkeletonRenderer_getBlendFunc : Invalid Native Object"); @@ -245,7 +256,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t arg 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; } @@ -254,20 +265,20 @@ bool js_cocos2dx_spine_SkeletonRenderer_getBlendFunc(JSContext *cx, uint32_t arg } bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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"); 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_spine_SkeletonRenderer_drawSkeleton : Error processing arguments"); cobj->drawSkeleton(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -276,13 +287,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_drawSkeleton(JSContext *cx, uint32_t arg } 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; } @@ -291,13 +303,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_updateWorldTransform(JSContext *cx, uint } bool js_cocos2dx_spine_SkeletonRenderer_initialize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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_initialize : Invalid Native Object"); if (argc == 0) { cobj->initialize(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -306,18 +319,18 @@ bool js_cocos2dx_spine_SkeletonRenderer_initialize(JSContext *cx, uint32_t argc, } 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; } @@ -326,7 +339,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_setDebugBonesEnabled(JSContext *cx, uint } 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_getDebugBonesEnabled : Invalid Native Object"); @@ -334,7 +348,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled(JSContext *cx, uint bool ret = cobj->getDebugBonesEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -343,7 +357,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_getDebugBonesEnabled(JSContext *cx, uint } 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_getTimeScale : Invalid Native Object"); @@ -351,7 +366,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_getTimeScale(JSContext *cx, uint32_t arg 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; } @@ -360,25 +375,25 @@ bool js_cocos2dx_spine_SkeletonRenderer_getTimeScale(JSContext *cx, uint32_t arg } bool js_cocos2dx_spine_SkeletonRenderer_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); spine::SkeletonRenderer* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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, 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->initWithFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -386,16 +401,16 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(JSContext *cx, uint32_t arg 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; } cobj->initWithFile(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -403,14 +418,14 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(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; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* ok = false; if (!ok) { ok = true; break; } cobj->initWithFile(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -418,17 +433,17 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(JSContext *cx, uint32_t arg 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; } cobj->initWithFile(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -438,18 +453,18 @@ bool js_cocos2dx_spine_SkeletonRenderer_initWithFile(JSContext *cx, uint32_t arg } 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; } @@ -458,20 +473,20 @@ bool js_cocos2dx_spine_SkeletonRenderer_setBlendFunc(JSContext *cx, uint32_t arg } bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setSkin : 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_spine_SkeletonRenderer_setSkin : Error processing arguments"); bool ret = cobj->setSkin(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -480,7 +495,8 @@ bool js_cocos2dx_spine_SkeletonRenderer_setSkin(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -488,7 +504,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc spSkeleton* ret = cobj->getSkeleton(); jsval jsret = JSVAL_NULL; jsret = spskeleton_to_jsval(cx, *ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -497,16 +513,16 @@ bool js_cocos2dx_spine_SkeletonRenderer_getSkeleton(JSContext *cx, uint32_t argc } 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; @@ -518,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; @@ -543,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); @@ -551,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* @@ -567,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; @@ -593,7 +609,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); @@ -602,10 +618,10 @@ bool js_cocos2dx_spine_SkeletonRenderer_createWithFile(JSContext *cx, uint32_t a } bool js_cocos2dx_spine_SkeletonRenderer_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); spine::SkeletonRenderer* cobj = NULL; do { if (argc == 1) { @@ -625,9 +641,13 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } while(0); @@ -638,7 +658,7 @@ bool js_cocos2dx_spine_SkeletonRenderer_constructor(JSContext *cx, uint32_t argc ok = false; if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + arg1 = JS::ToBoolean(args.get(1)); cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { @@ -651,9 +671,13 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } while(0); @@ -671,16 +695,20 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } 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; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* @@ -698,23 +726,27 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } 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; } cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -728,19 +760,23 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } 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; } cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -754,22 +790,26 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonRenderer"); } } 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; } cobj = new (std::nothrow) spine::SkeletonRenderer(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -783,17 +823,21 @@ bool js_cocos2dx_spine_SkeletonRenderer_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."); - 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, "spine::SkeletonRenderer"); + 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", 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_spine_SkeletonRenderer_constructor : wrong number of arguments"); @@ -807,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; @@ -821,8 +865,8 @@ 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[] = { @@ -857,7 +901,7 @@ 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, js_cocos2dx_spine_SkeletonRenderer_constructor, 0, // constructor properties, @@ -888,24 +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); } @@ -920,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; } @@ -929,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"); @@ -941,16 +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); largv[1] = spevent_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); } @@ -965,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; } @@ -974,7 +1018,8 @@ 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"); @@ -982,7 +1027,7 @@ bool js_cocos2dx_spine_SkeletonAnimation_getState(JSContext *cx, uint32_t argc, spAnimationState* ret = cobj->getState(); jsval jsret = JSVAL_NULL; jsret = spanimationstate_to_jsval(cx, *ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -991,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"); @@ -1003,16 +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); } @@ -1027,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; } @@ -1036,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"); @@ -1047,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; } @@ -1063,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"); @@ -1075,15 +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); } @@ -1098,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; } @@ -1107,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; } @@ -1127,25 +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); } @@ -1160,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; } @@ -1169,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"); @@ -1181,15 +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); } @@ -1204,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; } @@ -1213,25 +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); largv[1] = spevent_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); } @@ -1246,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; } @@ -1255,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"); @@ -1265,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; } @@ -1279,24 +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); } @@ -1311,7 +1356,7 @@ 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; } @@ -1320,13 +1365,14 @@ bool js_cocos2dx_spine_SkeletonAnimation_setEndListener(JSContext *cx, uint32_t } bool js_cocos2dx_spine_SkeletonAnimation_initialize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1335,13 +1381,14 @@ bool js_cocos2dx_spine_SkeletonAnimation_initialize(JSContext *cx, uint32_t argc } 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; } @@ -1350,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; } @@ -1375,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"); @@ -1386,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; } @@ -1402,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; @@ -1423,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; @@ -1448,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); @@ -1456,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* @@ -1472,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; @@ -1498,7 +1545,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); @@ -1507,10 +1554,10 @@ bool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t } bool js_cocos2dx_spine_SkeletonAnimation_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); spine::SkeletonAnimation* cobj = NULL; do { if (argc == 1) { @@ -1530,9 +1577,13 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); @@ -1550,16 +1601,20 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } 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; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* @@ -1577,23 +1632,27 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } 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; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1607,19 +1666,23 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } 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; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1633,22 +1696,26 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } 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; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1662,17 +1729,21 @@ bool js_cocos2dx_spine_SkeletonAnimation_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."); - 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, "spine::SkeletonAnimation"); + 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", 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_spine_SkeletonAnimation_constructor : wrong number of arguments"); @@ -1688,21 +1759,21 @@ void js_spine_SkeletonAnimation_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_spine_SkeletonAnimation_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()); spine::SkeletonAnimation *nobj = new (std::nothrow) spine::SkeletonAnimation(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); + 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", 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_spine_SkeletonAnimation(JSContext *cx, JSObject *global) { +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; @@ -1716,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[] = { @@ -1748,7 +1819,7 @@ 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, js_cocos2dx_spine_SkeletonAnimation_constructor, 0, // constructor properties, @@ -1774,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 09ee935df3..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,8 +10,8 @@ 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_getDebugSlotsEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_spine_SkeletonRenderer_setAttachment(JSContext *cx, uint32_t argc, jsval *vp); @@ -41,8 +41,8 @@ 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); 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 faa174d43d..23da23e9d6 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -5,10 +5,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; @@ -19,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; } @@ -32,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_cocostudio_ActionObject_class; @@ -42,18 +47,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; } @@ -62,13 +67,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; } @@ -77,18 +83,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; } @@ -97,18 +103,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; } @@ -117,7 +123,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"); @@ -125,7 +132,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; } @@ -134,7 +141,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"); @@ -142,7 +150,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; } @@ -151,13 +159,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; } @@ -166,12 +175,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"); @@ -179,16 +188,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); @@ -196,7 +205,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); @@ -206,7 +215,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"); @@ -214,7 +224,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; } @@ -223,25 +233,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; } @@ -250,7 +260,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"); @@ -258,7 +269,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; } @@ -267,9 +278,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"); @@ -278,9 +289,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"); @@ -288,16 +299,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; } @@ -306,25 +317,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; } @@ -333,7 +344,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"); @@ -341,7 +353,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; } @@ -350,7 +362,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"); @@ -358,7 +371,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; } @@ -367,18 +380,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; } @@ -387,18 +400,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; } @@ -407,18 +420,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; } @@ -427,7 +440,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); @@ -441,13 +454,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; } @@ -457,7 +473,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; @@ -471,8 +487,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[] = { @@ -501,7 +517,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, @@ -532,17 +548,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; @@ -554,7 +570,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; } @@ -563,17 +579,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; @@ -585,7 +601,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; } @@ -594,9 +610,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"); @@ -605,19 +621,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"); @@ -626,7 +642,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; } @@ -635,28 +651,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"); @@ -672,7 +688,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); @@ -680,10 +696,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; @@ -695,7 +711,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); @@ -705,13 +721,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; } @@ -720,9 +737,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"); @@ -731,6 +749,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; @@ -742,7 +761,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"); @@ -755,7 +774,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; @@ -769,8 +788,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[] = { @@ -790,7 +809,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, @@ -821,7 +840,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"); @@ -829,7 +849,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; } @@ -838,18 +858,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; } @@ -858,6 +878,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; @@ -869,7 +890,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"); @@ -878,7 +899,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); @@ -892,13 +913,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; } @@ -908,7 +932,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; @@ -922,8 +946,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[] = { @@ -939,7 +963,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, @@ -970,15 +994,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; @@ -990,7 +1014,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; } @@ -999,25 +1023,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; } @@ -1026,6 +1050,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; @@ -1037,7 +1062,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"); @@ -1046,7 +1071,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); @@ -1060,13 +1085,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; } @@ -1076,7 +1104,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; @@ -1090,8 +1118,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[] = { @@ -1107,7 +1135,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, @@ -1138,15 +1166,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; @@ -1158,7 +1186,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; } @@ -1167,7 +1195,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"); @@ -1175,7 +1204,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; } @@ -1184,25 +1213,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; } @@ -1211,6 +1240,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; @@ -1222,7 +1252,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"); @@ -1231,7 +1261,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); @@ -1245,13 +1275,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; } @@ -1261,7 +1294,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; @@ -1275,8 +1308,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[] = { @@ -1293,7 +1326,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, @@ -1324,7 +1357,8 @@ JSObject *jsb_cocostudio_ContourData_prototype; bool js_cocos2dx_studio_ContourData_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::ContourData* cobj = (cocostudio::ContourData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ContourData_init : Invalid Native Object"); @@ -1332,7 +1366,7 @@ bool js_cocos2dx_studio_ContourData_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; } @@ -1341,18 +1375,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1361,6 +1395,7 @@ bool js_cocos2dx_studio_ContourData_addVertex(JSContext *cx, uint32_t argc, jsva } 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; @@ -1372,7 +1407,7 @@ bool js_cocos2dx_studio_ContourData_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_ContourData_create : wrong number of arguments"); @@ -1381,7 +1416,7 @@ bool js_cocos2dx_studio_ContourData_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_studio_ContourData_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::ContourData* cobj = new (std::nothrow) cocostudio::ContourData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1395,13 +1430,16 @@ bool js_cocos2dx_studio_ContourData_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::ContourData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ContourData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1411,7 +1449,7 @@ 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, JSObject *global) { +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; @@ -1425,8 +1463,8 @@ void js_register_cocos2dx_studio_ContourData(JSContext *cx, JSObject *global) { jsb_cocostudio_ContourData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1442,7 +1480,7 @@ void js_register_cocos2dx_studio_ContourData(JSContext *cx, JSObject *global) { jsb_cocostudio_ContourData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_ContourData_class, js_cocos2dx_studio_ContourData_constructor, 0, // constructor properties, @@ -1473,15 +1511,15 @@ JSObject *jsb_cocostudio_TextureData_prototype; bool js_cocos2dx_studio_TextureData_getContourData(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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::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, argv[0], (int32_t *)&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; @@ -1493,7 +1531,7 @@ bool js_cocos2dx_studio_TextureData_getContourData(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1502,7 +1540,8 @@ bool js_cocos2dx_studio_TextureData_getContourData(JSContext *cx, uint32_t argc, } bool js_cocos2dx_studio_TextureData_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::TextureData* cobj = (cocostudio::TextureData *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_TextureData_init : Invalid Native Object"); @@ -1510,7 +1549,7 @@ bool js_cocos2dx_studio_TextureData_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; } @@ -1519,25 +1558,25 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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::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 (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } 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::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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1546,6 +1585,7 @@ bool js_cocos2dx_studio_TextureData_addContourData(JSContext *cx, uint32_t argc, } 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; @@ -1557,7 +1597,7 @@ bool js_cocos2dx_studio_TextureData_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_TextureData_create : wrong number of arguments"); @@ -1566,7 +1606,7 @@ bool js_cocos2dx_studio_TextureData_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_studio_TextureData_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::TextureData* cobj = new (std::nothrow) cocostudio::TextureData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -1580,13 +1620,16 @@ bool js_cocos2dx_studio_TextureData_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::TextureData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::TextureData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -1596,7 +1639,7 @@ 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, JSObject *global) { +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; @@ -1610,8 +1653,8 @@ void js_register_cocos2dx_studio_TextureData(JSContext *cx, JSObject *global) { jsb_cocostudio_TextureData_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1628,7 +1671,7 @@ void js_register_cocos2dx_studio_TextureData(JSContext *cx, JSObject *global) { jsb_cocostudio_TextureData_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocostudio_TextureData_class, js_cocos2dx_studio_TextureData_constructor, 0, // constructor properties, @@ -1659,9 +1702,9 @@ 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"); @@ -1670,13 +1713,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; } @@ -1685,13 +1728,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; } @@ -1700,7 +1744,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"); @@ -1708,7 +1753,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; } @@ -1717,13 +1762,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; } @@ -1732,18 +1778,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; } @@ -1752,13 +1798,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; } @@ -1767,18 +1814,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; } @@ -1787,7 +1834,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"); @@ -1795,7 +1843,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; } @@ -1804,7 +1852,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"); @@ -1812,7 +1861,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; } @@ -1821,7 +1870,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"); @@ -1829,7 +1879,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; } @@ -1838,18 +1888,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; } @@ -1858,7 +1908,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"); @@ -1866,7 +1917,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; } @@ -1875,7 +1926,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"); @@ -1883,7 +1935,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; } @@ -1892,7 +1944,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"); @@ -1900,7 +1953,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; } @@ -1909,18 +1962,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; } @@ -1929,18 +1982,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; } @@ -1949,7 +2002,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); @@ -1963,13 +2016,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; } @@ -1979,7 +2035,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; @@ -1993,8 +2049,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[] = { @@ -2021,7 +2077,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, @@ -2052,7 +2108,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"); @@ -2067,7 +2124,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; } @@ -2076,18 +2133,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; } @@ -2096,9 +2153,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"); @@ -2109,20 +2166,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; } @@ -2131,18 +2188,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; } @@ -2151,18 +2208,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"); @@ -2171,7 +2228,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; } @@ -2180,25 +2237,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; } @@ -2207,14 +2264,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"); @@ -2230,7 +2287,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"); @@ -2239,7 +2296,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); @@ -2253,13 +2310,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; } @@ -2270,7 +2330,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; @@ -2284,8 +2344,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[] = { @@ -2305,7 +2365,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, @@ -2340,7 +2400,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; @@ -2354,8 +2414,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[] = { @@ -2366,7 +2426,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, @@ -2401,7 +2461,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; @@ -2415,8 +2475,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[] = { @@ -2427,7 +2487,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, @@ -2458,7 +2518,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"); @@ -2473,7 +2534,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; } @@ -2482,7 +2543,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"); @@ -2490,7 +2552,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; } @@ -2499,7 +2561,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"); @@ -2507,7 +2570,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; } @@ -2516,18 +2579,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; } @@ -2536,13 +2599,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; } @@ -2551,12 +2615,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"); @@ -2564,9 +2628,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"); @@ -2575,7 +2639,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); @@ -2585,7 +2649,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); @@ -2595,18 +2659,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; } @@ -2615,25 +2679,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; } @@ -2642,16 +2706,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"); @@ -2667,7 +2731,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); @@ -2684,7 +2748,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); @@ -2697,7 +2761,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; @@ -2711,8 +2775,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[] = { @@ -2734,7 +2798,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, @@ -2765,7 +2829,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"); @@ -2780,7 +2845,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; } @@ -2789,7 +2854,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"); @@ -2804,7 +2870,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; } @@ -2813,25 +2879,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; } @@ -2840,7 +2906,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"); @@ -2848,7 +2915,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; } @@ -2857,25 +2924,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; } @@ -2884,7 +2951,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"); @@ -2899,7 +2967,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; } @@ -2908,25 +2976,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; } @@ -2935,6 +3003,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; @@ -2946,7 +3015,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"); @@ -2959,7 +3028,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; @@ -2973,8 +3042,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[] = { @@ -2995,7 +3064,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, @@ -3026,7 +3095,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"); @@ -3041,7 +3111,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; } @@ -3050,7 +3120,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"); @@ -3065,7 +3136,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; } @@ -3074,7 +3145,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"); @@ -3082,7 +3154,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; } @@ -3091,25 +3163,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; } @@ -3118,7 +3190,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"); @@ -3126,7 +3199,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; } @@ -3135,18 +3208,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; } @@ -3155,18 +3228,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; } @@ -3175,18 +3248,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"); @@ -3195,7 +3268,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; } @@ -3204,7 +3277,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"); @@ -3212,7 +3286,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; } @@ -3221,7 +3295,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"); @@ -3229,7 +3304,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; } @@ -3238,12 +3313,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"); @@ -3251,19 +3326,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); @@ -3272,19 +3347,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); @@ -3294,27 +3369,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); @@ -3322,12 +3397,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); @@ -3337,25 +3412,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; } @@ -3364,20 +3439,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; } @@ -3386,20 +3461,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; } @@ -3408,7 +3483,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"); @@ -3416,7 +3492,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; } @@ -3425,15 +3501,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; @@ -3445,7 +3521,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; } @@ -3454,7 +3530,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"); @@ -3462,7 +3539,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; } @@ -3471,7 +3548,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"); @@ -3479,7 +3557,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; } @@ -3488,7 +3566,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"); @@ -3496,7 +3575,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; } @@ -3505,7 +3584,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"); @@ -3513,7 +3593,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; } @@ -3522,18 +3602,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; } @@ -3542,14 +3622,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"); @@ -3565,7 +3645,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"); @@ -3574,7 +3654,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); @@ -3588,13 +3668,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; } @@ -3604,7 +3687,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; @@ -3618,8 +3701,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[] = { @@ -3655,7 +3738,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, @@ -3686,7 +3769,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"); @@ -3694,7 +3778,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; } @@ -3703,18 +3787,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; } @@ -3723,7 +3807,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"); @@ -3731,7 +3816,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; } @@ -3740,13 +3825,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; } @@ -3755,7 +3841,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"); @@ -3770,7 +3857,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; } @@ -3779,7 +3866,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"); @@ -3787,7 +3875,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; } @@ -3796,25 +3884,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; } @@ -3823,7 +3911,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"); @@ -3838,7 +3927,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; } @@ -3847,7 +3936,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"); @@ -3862,7 +3952,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; } @@ -3871,7 +3961,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"); @@ -3886,7 +3977,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; } @@ -3895,13 +3986,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; } @@ -3910,18 +4002,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; } @@ -3930,7 +4022,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"); @@ -3938,7 +4031,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; } @@ -3947,18 +4040,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; } @@ -3967,25 +4060,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; } @@ -3994,20 +4087,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; } @@ -4016,25 +4109,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; } @@ -4043,12 +4136,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"); @@ -4056,19 +4149,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); @@ -4077,19 +4170,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); @@ -4099,18 +4192,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; } @@ -4119,7 +4212,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"); @@ -4127,7 +4221,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; } @@ -4136,18 +4230,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; } @@ -4156,7 +4250,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"); @@ -4171,7 +4266,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; } @@ -4180,7 +4275,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"); @@ -4195,7 +4291,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; } @@ -4204,20 +4300,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; } @@ -4226,20 +4322,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; } @@ -4248,25 +4344,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; } @@ -4275,18 +4371,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; } @@ -4295,9 +4391,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"); @@ -4305,17 +4401,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; } @@ -4324,25 +4420,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; } @@ -4351,7 +4447,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"); @@ -4359,7 +4456,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; } @@ -4368,7 +4465,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"); @@ -4383,7 +4481,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; } @@ -4392,7 +4490,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"); @@ -4407,7 +4506,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; } @@ -4416,13 +4515,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; @@ -4434,7 +4533,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); @@ -4451,7 +4550,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); @@ -4460,7 +4559,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); @@ -4474,13 +4573,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; } @@ -4491,7 +4593,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; @@ -4505,8 +4607,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[] = { @@ -4552,7 +4654,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, @@ -4583,6 +4685,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; @@ -4594,7 +4697,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"); @@ -4608,7 +4711,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; @@ -4622,8 +4725,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[] = { @@ -4637,7 +4740,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, @@ -4668,7 +4771,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"); @@ -4676,7 +4780,7 @@ 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; } @@ -4685,13 +4789,14 @@ bool js_cocos2dx_studio_ArmatureAnimation_getSpeedScale(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ArmatureAnimation_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::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); + args.rval().setUndefined(); return true; } @@ -4700,18 +4805,18 @@ bool js_cocos2dx_studio_ArmatureAnimation_pause(JSContext *cx, uint32_t argc, js } 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_setSpeedScale : 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_ArmatureAnimation_setSpeedScale : Error processing arguments"); cobj->setSpeedScale(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4720,18 +4825,18 @@ bool js_cocos2dx_studio_ArmatureAnimation_setSpeedScale(JSContext *cx, uint32_t } 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_init : 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"); @@ -4740,7 +4845,7 @@ bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsv 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; } @@ -4749,40 +4854,40 @@ bool js_cocos2dx_studio_ArmatureAnimation_init(JSContext *cx, uint32_t argc, jsv } 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_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; } @@ -4791,40 +4896,40 @@ bool js_cocos2dx_studio_ArmatureAnimation_playWithIndexes(JSContext *cx, uint32_ } bool js_cocos2dx_studio_ArmatureAnimation_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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); 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_ArmatureAnimation_play : Error processing arguments"); cobj->play(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4833,18 +4938,18 @@ bool js_cocos2dx_studio_ArmatureAnimation_play(JSContext *cx, uint32_t argc, jsv } 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_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_ArmatureAnimation_gotoAndPause : Error processing arguments"); cobj->gotoAndPause(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4853,13 +4958,14 @@ bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPause(JSContext *cx, uint32_t a } bool js_cocos2dx_studio_ArmatureAnimation_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::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); + args.rval().setUndefined(); return true; } @@ -4868,13 +4974,14 @@ bool js_cocos2dx_studio_ArmatureAnimation_resume(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_studio_ArmatureAnimation_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::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); + args.rval().setUndefined(); return true; } @@ -4883,18 +4990,18 @@ bool js_cocos2dx_studio_ArmatureAnimation_stop(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_studio_ArmatureAnimation_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::ArmatureAnimation* cobj = (cocostudio::ArmatureAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ArmatureAnimation_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_ArmatureAnimation_update : Error processing arguments"); cobj->update(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4903,7 +5010,8 @@ bool js_cocos2dx_studio_ArmatureAnimation_update(JSContext *cx, uint32_t argc, j } 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"); @@ -4918,7 +5026,7 @@ 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; } @@ -4927,40 +5035,40 @@ bool js_cocos2dx_studio_ArmatureAnimation_getAnimationData(JSContext *cx, uint32 } bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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"); 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_ArmatureAnimation_playWithIndex : Error processing arguments"); cobj->playWithIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4969,7 +5077,8 @@ bool js_cocos2dx_studio_ArmatureAnimation_playWithIndex(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -4977,7 +5086,7 @@ bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, ui std::string ret = cobj->getCurrentMovementID(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -4986,25 +5095,25 @@ bool js_cocos2dx_studio_ArmatureAnimation_getCurrentMovementID(JSContext *cx, ui } 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_setAnimationData : Invalid Native Object"); if (argc == 1) { cocostudio::AnimationData* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } 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); 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); + args.rval().setUndefined(); return true; } @@ -5013,18 +5122,18 @@ bool js_cocos2dx_studio_ArmatureAnimation_setAnimationData(JSContext *cx, uint32 } 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_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_ArmatureAnimation_gotoAndPlay : Error processing arguments"); cobj->gotoAndPlay(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -5033,40 +5142,40 @@ bool js_cocos2dx_studio_ArmatureAnimation_gotoAndPlay(JSContext *cx, uint32_t ar } 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; } @@ -5075,7 +5184,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"); @@ -5083,7 +5193,7 @@ 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; } @@ -5092,14 +5202,14 @@ bool js_cocos2dx_studio_ArmatureAnimation_getMovementCount(JSContext *cx, uint32 } 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"); @@ -5115,7 +5225,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"); @@ -5124,7 +5234,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); @@ -5138,13 +5248,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; } @@ -5155,7 +5268,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; @@ -5169,8 +5282,8 @@ 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[] = { @@ -5201,7 +5314,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, @@ -5232,7 +5345,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"); @@ -5240,7 +5354,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; } @@ -5249,18 +5363,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; } @@ -5269,46 +5383,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; } @@ -5317,28 +5431,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); @@ -5346,10 +5460,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); @@ -5359,18 +5473,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; } @@ -5379,15 +5493,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; @@ -5399,7 +5513,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; } @@ -5408,15 +5522,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; @@ -5428,7 +5542,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; } @@ -5437,15 +5551,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; @@ -5457,7 +5571,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; } @@ -5466,46 +5580,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; } @@ -5514,7 +5628,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"); @@ -5522,7 +5637,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; } @@ -5531,18 +5646,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; } @@ -5551,7 +5666,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"); @@ -5559,7 +5675,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; } @@ -5568,18 +5684,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; } @@ -5588,46 +5704,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; } @@ -5636,7 +5752,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"); @@ -5644,7 +5761,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; } @@ -5653,32 +5770,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; } @@ -5687,9 +5804,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"); @@ -5698,6 +5816,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; @@ -5709,7 +5828,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"); @@ -5722,7 +5841,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; @@ -5736,8 +5855,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[] = { @@ -5768,7 +5887,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, @@ -5799,15 +5918,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; @@ -5819,7 +5938,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; } @@ -5828,9 +5947,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"); @@ -5838,17 +5957,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; } @@ -5857,25 +5976,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; } @@ -5884,17 +6003,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; @@ -5906,7 +6025,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; } @@ -5915,7 +6034,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"); @@ -5923,7 +6043,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; } @@ -5932,18 +6052,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; } @@ -5952,13 +6072,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; } @@ -5967,7 +6088,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"); @@ -5982,7 +6104,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; } @@ -5991,9 +6113,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"); @@ -6001,17 +6123,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; } @@ -6020,7 +6142,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"); @@ -6035,7 +6158,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; } @@ -6044,25 +6167,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"); @@ -6071,7 +6194,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); @@ -6079,12 +6202,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); @@ -6094,25 +6217,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; } @@ -6121,25 +6244,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; } @@ -6148,7 +6271,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"); @@ -6156,7 +6280,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; } @@ -6165,25 +6289,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; } @@ -6192,9 +6316,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"); @@ -6202,17 +6326,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; } @@ -6221,7 +6345,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"); @@ -6236,7 +6361,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; } @@ -6245,7 +6370,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"); @@ -6253,7 +6379,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; } @@ -6262,7 +6388,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"); @@ -6270,7 +6397,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; } @@ -6279,7 +6406,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"); @@ -6294,7 +6422,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; } @@ -6303,7 +6431,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"); @@ -6311,7 +6440,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; } @@ -6320,18 +6449,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; } @@ -6340,7 +6469,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"); @@ -6348,7 +6478,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; } @@ -6357,13 +6487,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; @@ -6375,7 +6505,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); @@ -6392,7 +6522,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); @@ -6400,13 +6530,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"); @@ -6422,7 +6552,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); @@ -6431,7 +6561,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); @@ -6445,13 +6575,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; } @@ -6464,21 +6597,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; @@ -6492,8 +6625,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[] = { @@ -6531,7 +6664,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, @@ -6562,7 +6695,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"); @@ -6577,7 +6711,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; } @@ -6586,7 +6720,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"); @@ -6594,7 +6729,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; } @@ -6603,7 +6738,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"); @@ -6611,7 +6747,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; } @@ -6620,13 +6756,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; } @@ -6635,25 +6772,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; } @@ -6662,13 +6799,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; @@ -6680,7 +6817,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); @@ -6697,7 +6834,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); @@ -6706,11 +6843,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; @@ -6722,7 +6859,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"); @@ -6731,7 +6868,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); @@ -6745,13 +6882,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; } @@ -6762,7 +6902,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; @@ -6776,8 +6916,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[] = { @@ -6797,7 +6937,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, @@ -6828,32 +6968,32 @@ 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; } @@ -6862,32 +7002,32 @@ bool js_cocos2dx_studio_ComAttribute_getFloat(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(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])); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -6896,32 +7036,32 @@ bool js_cocos2dx_studio_ComAttribute_getBool(JSContext *cx, uint32_t argc, jsval } 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; } @@ -6930,20 +7070,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; } @@ -6952,20 +7092,20 @@ 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; } @@ -6974,20 +7114,20 @@ bool js_cocos2dx_studio_ComAttribute_setString(JSContext *cx, uint32_t argc, jsv } 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_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; } @@ -6996,20 +7136,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; } @@ -7018,32 +7158,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; } @@ -7052,20 +7192,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; } @@ -7074,6 +7214,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; @@ -7085,7 +7226,7 @@ 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"); @@ -7094,7 +7235,7 @@ bool js_cocos2dx_studio_ComAttribute_create(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_studio_ComAttribute_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::ComAttribute* cobj = new (std::nothrow) cocostudio::ComAttribute(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7108,13 +7249,16 @@ bool js_cocos2dx_studio_ComAttribute_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::ComAttribute"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComAttribute"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7125,7 +7269,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; @@ -7139,8 +7283,8 @@ 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[] = { @@ -7163,7 +7307,7 @@ 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, js_cocos2dx_studio_ComAttribute_constructor, 0, // constructor properties, @@ -7194,13 +7338,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; } @@ -7209,7 +7354,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"); @@ -7217,7 +7363,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; } @@ -7226,18 +7372,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; } @@ -7246,7 +7392,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"); @@ -7254,7 +7401,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; } @@ -7263,7 +7410,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"); @@ -7271,7 +7419,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; } @@ -7280,18 +7428,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; } @@ -7300,13 +7448,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; } @@ -7315,19 +7464,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); @@ -7335,9 +7484,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); @@ -7347,13 +7496,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; } @@ -7362,7 +7512,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"); @@ -7370,7 +7521,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; } @@ -7379,7 +7530,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"); @@ -7387,7 +7539,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; } @@ -7396,13 +7548,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; } @@ -7411,13 +7564,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; } @@ -7426,18 +7580,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; } @@ -7446,22 +7600,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); @@ -7469,12 +7623,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); @@ -7482,7 +7636,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); @@ -7492,24 +7646,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); @@ -7517,14 +7671,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); @@ -7534,7 +7688,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); @@ -7544,18 +7698,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; } @@ -7564,18 +7718,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; } @@ -7584,18 +7738,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; } @@ -7604,13 +7758,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; } @@ -7619,18 +7774,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; } @@ -7639,13 +7794,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; } @@ -7654,18 +7810,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; } @@ -7674,18 +7830,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; } @@ -7694,7 +7850,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"); @@ -7702,7 +7859,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; } @@ -7711,18 +7868,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; } @@ -7731,6 +7888,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; @@ -7742,7 +7900,7 @@ 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"); @@ -7751,7 +7909,7 @@ bool js_cocos2dx_studio_ComAudio_create(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_studio_ComAudio_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::ComAudio* cobj = new (std::nothrow) cocostudio::ComAudio(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -7765,13 +7923,16 @@ bool js_cocos2dx_studio_ComAudio_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::ComAudio"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComAudio"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -7782,7 +7943,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; @@ -7796,8 +7957,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[] = { @@ -7837,7 +7998,7 @@ 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, js_cocos2dx_studio_ComAudio_constructor, 0, // constructor properties, @@ -7868,7 +8029,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"); @@ -7876,7 +8038,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; } @@ -7885,18 +8047,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; } @@ -7905,7 +8067,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"); @@ -7913,7 +8076,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; } @@ -7922,18 +8085,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; } @@ -7942,7 +8105,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"); @@ -7950,7 +8114,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; } @@ -7959,7 +8123,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"); @@ -7967,7 +8132,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; } @@ -7976,18 +8141,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; } @@ -7996,7 +8161,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"); @@ -8004,7 +8170,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; } @@ -8013,18 +8179,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; } @@ -8033,18 +8199,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; } @@ -8057,7 +8223,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; @@ -8071,8 +8237,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[] = { @@ -8093,7 +8259,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, @@ -8124,6 +8290,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; @@ -8135,7 +8302,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"); @@ -8144,7 +8311,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); @@ -8158,13 +8325,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; } @@ -8177,21 +8347,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; @@ -8205,8 +8375,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[] = { @@ -8221,7 +8391,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, @@ -8252,7 +8422,8 @@ JSObject *jsb_cocostudio_ComRender_prototype; 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"); @@ -8267,7 +8438,7 @@ 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; } @@ -8276,25 +8447,25 @@ bool js_cocos2dx_studio_ComRender_getNode(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_studio_ComRender_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::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; } + if (!args.get(0).isObject()) { ok = false; break; } js_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_ComRender_setNode : Error processing arguments"); cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8303,23 +8474,23 @@ bool js_cocos2dx_studio_ComRender_setNode(JSContext *cx, uint32_t argc, jsval *v } 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; @@ -8331,7 +8502,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); @@ -8348,7 +8519,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); @@ -8357,25 +8528,25 @@ bool js_cocos2dx_studio_ComRender_create(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 = NULL; + JS::RootedObject obj(cx); cocostudio::ComRender* cobj = NULL; 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; } cobj = new (std::nothrow) cocostudio::ComRender(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -8389,9 +8560,13 @@ bool js_cocos2dx_studio_ComRender_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."); - 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, "cocostudio::ComRender"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::ComRender"); } } while(0); @@ -8409,17 +8584,21 @@ bool js_cocos2dx_studio_ComRender_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."); - 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, "cocostudio::ComRender"); + 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", 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_studio_ComRender_constructor : wrong number of arguments"); @@ -8433,7 +8612,7 @@ 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) { +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; @@ -8447,8 +8626,8 @@ void js_register_cocos2dx_studio_ComRender(JSContext *cx, JSObject *global) { 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[] = { @@ -8464,7 +8643,7 @@ void js_register_cocos2dx_studio_ComRender(JSContext *cx, JSObject *global) { jsb_cocostudio_ComRender_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Component_prototype, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), jsb_cocostudio_ComRender_class, js_cocos2dx_studio_ComRender_constructor, 0, // constructor properties, @@ -8495,7 +8674,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"); @@ -8510,7 +8690,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; } @@ -8519,25 +8699,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; } @@ -8546,25 +8726,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; } @@ -8573,7 +8753,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"); @@ -8581,7 +8762,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; } @@ -8590,7 +8771,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"); @@ -8598,7 +8780,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; } @@ -8607,18 +8789,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; } @@ -8627,7 +8809,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"); @@ -8635,7 +8818,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; } @@ -8644,18 +8827,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; } @@ -8664,18 +8847,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; } @@ -8684,7 +8867,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"); @@ -8699,7 +8883,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; } @@ -8708,7 +8892,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"); @@ -8723,7 +8908,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; } @@ -8736,7 +8921,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; @@ -8750,8 +8935,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[] = { @@ -8773,7 +8958,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, @@ -8804,7 +8989,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"); @@ -8812,7 +8998,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; } @@ -8821,18 +9007,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; } @@ -8841,6 +9027,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; @@ -8852,7 +9039,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"); @@ -8861,7 +9048,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); @@ -8875,13 +9062,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; } @@ -8892,7 +9082,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; @@ -8906,8 +9096,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[] = { @@ -8923,7 +9113,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, @@ -8954,7 +9144,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"); @@ -8962,7 +9153,7 @@ 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; } @@ -8971,25 +9162,25 @@ bool js_cocos2dx_studio_TextureFrame_getTextureName(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_TextureFrame_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::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; } + if (!args.get(0).isObject()) { ok = false; break; } js_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_TextureFrame_setNode : Error processing arguments"); cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8998,18 +9189,18 @@ bool js_cocos2dx_studio_TextureFrame_setNode(JSContext *cx, uint32_t argc, jsval } 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; } @@ -9018,6 +9209,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; @@ -9029,7 +9221,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"); @@ -9038,7 +9230,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); @@ -9052,13 +9244,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; } @@ -9069,7 +9264,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; @@ -9083,8 +9278,8 @@ 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[] = { @@ -9101,7 +9296,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, @@ -9132,18 +9327,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; } @@ -9152,7 +9347,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"); @@ -9160,7 +9356,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; } @@ -9169,6 +9365,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; @@ -9180,7 +9377,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"); @@ -9189,7 +9386,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); @@ -9203,13 +9400,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; } @@ -9220,7 +9420,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; @@ -9234,8 +9434,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[] = { @@ -9251,7 +9451,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, @@ -9282,7 +9482,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"); @@ -9290,7 +9491,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; } @@ -9299,18 +9500,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; } @@ -9319,18 +9520,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; } @@ -9339,7 +9540,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"); @@ -9347,7 +9549,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; } @@ -9356,6 +9558,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; @@ -9367,7 +9570,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"); @@ -9376,7 +9579,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); @@ -9390,13 +9593,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; } @@ -9407,7 +9613,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; @@ -9421,8 +9627,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[] = { @@ -9440,7 +9646,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, @@ -9471,6 +9677,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; @@ -9482,7 +9689,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"); @@ -9491,7 +9698,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); @@ -9505,13 +9712,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; } @@ -9522,7 +9732,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; @@ -9536,8 +9746,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[] = { @@ -9551,7 +9761,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, @@ -9582,7 +9792,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"); @@ -9590,7 +9801,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; } @@ -9599,7 +9810,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"); @@ -9607,7 +9819,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; } @@ -9616,18 +9828,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; } @@ -9636,18 +9848,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; } @@ -9656,18 +9868,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; } @@ -9676,7 +9888,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"); @@ -9684,7 +9897,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; } @@ -9693,6 +9906,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; @@ -9704,7 +9918,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"); @@ -9713,7 +9927,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); @@ -9727,13 +9941,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; } @@ -9744,7 +9961,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; @@ -9758,8 +9975,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[] = { @@ -9779,7 +9996,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, @@ -9810,18 +10027,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; } @@ -9830,18 +10047,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; } @@ -9850,7 +10067,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"); @@ -9858,7 +10076,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; } @@ -9867,7 +10085,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"); @@ -9875,7 +10094,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; } @@ -9884,18 +10103,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; } @@ -9904,6 +10123,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; @@ -9915,7 +10135,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"); @@ -9924,7 +10144,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); @@ -9938,13 +10158,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; } @@ -9955,7 +10178,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; @@ -9969,8 +10192,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[] = { @@ -9989,7 +10212,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, @@ -10020,18 +10243,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; } @@ -10040,7 +10263,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"); @@ -10048,7 +10272,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; } @@ -10057,6 +10281,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; @@ -10068,7 +10293,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"); @@ -10077,7 +10302,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); @@ -10091,13 +10316,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; } @@ -10108,7 +10336,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; @@ -10122,8 +10350,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[] = { @@ -10139,7 +10367,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, @@ -10170,7 +10398,8 @@ JSObject *jsb_cocostudio_timeline_InnerActionFrame_prototype; bool js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -10178,7 +10407,7 @@ bool js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex(JSContext *cx, uint32_ int ret = cobj->getEndFrameIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10187,7 +10416,8 @@ bool js_cocos2dx_studio_InnerActionFrame_getEndFrameIndex(JSContext *cx, uint32_ } bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -10195,7 +10425,7 @@ bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint3 int ret = cobj->getStartFrameIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10204,7 +10434,8 @@ bool js_cocos2dx_studio_InnerActionFrame_getStartFrameIndex(JSContext *cx, uint3 } 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"); @@ -10212,7 +10443,7 @@ 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; } @@ -10221,18 +10452,18 @@ bool js_cocos2dx_studio_InnerActionFrame_getInnerActionType(JSContext *cx, uint3 } bool js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setEndFrameIndex : 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_setEndFrameIndex : Error processing arguments"); cobj->setEndFrameIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10241,18 +10472,18 @@ bool js_cocos2dx_studio_InnerActionFrame_setEndFrameIndex(JSContext *cx, uint32_ } bool js_cocos2dx_studio_InnerActionFrame_setEnterWithName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setEnterWithName : 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_InnerActionFrame_setEnterWithName : Error processing arguments"); cobj->setEnterWithName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10261,18 +10492,18 @@ bool js_cocos2dx_studio_InnerActionFrame_setEnterWithName(JSContext *cx, uint32_ } bool js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setSingleFrameIndex : 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_setSingleFrameIndex : Error processing arguments"); cobj->setSingleFrameIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10281,18 +10512,18 @@ bool js_cocos2dx_studio_InnerActionFrame_setSingleFrameIndex(JSContext *cx, uint } 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; } @@ -10301,7 +10532,8 @@ bool js_cocos2dx_studio_InnerActionFrame_setStartFrameIndex(JSContext *cx, uint3 } bool js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -10309,7 +10541,7 @@ bool js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex(JSContext *cx, uint int ret = cobj->getSingleFrameIndex(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10318,18 +10550,18 @@ bool js_cocos2dx_studio_InnerActionFrame_getSingleFrameIndex(JSContext *cx, uint } 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; } @@ -10338,18 +10570,18 @@ bool js_cocos2dx_studio_InnerActionFrame_setInnerActionType(JSContext *cx, uint3 } bool js_cocos2dx_studio_InnerActionFrame_setAnimationName(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setAnimationName : 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_InnerActionFrame_setAnimationName : Error processing arguments"); cobj->setAnimationName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10358,6 +10590,7 @@ bool js_cocos2dx_studio_InnerActionFrame_setAnimationName(JSContext *cx, uint32_ } 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; @@ -10369,7 +10602,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"); @@ -10378,7 +10611,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); @@ -10392,13 +10625,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; } @@ -10409,7 +10645,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; @@ -10423,8 +10659,8 @@ 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[] = { @@ -10448,7 +10684,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, @@ -10479,7 +10715,8 @@ 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::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_getAlpha : Invalid Native Object"); @@ -10487,7 +10724,7 @@ bool js_cocos2dx_studio_ColorFrame_getAlpha(JSContext *cx, uint32_t argc, jsval uint16_t ret = cobj->getAlpha(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10496,7 +10733,8 @@ bool js_cocos2dx_studio_ColorFrame_getAlpha(JSContext *cx, uint32_t argc, jsval } 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"); @@ -10504,7 +10742,7 @@ 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; } @@ -10513,18 +10751,18 @@ bool js_cocos2dx_studio_ColorFrame_getColor(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ColorFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_setAlpha : 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_studio_ColorFrame_setAlpha : Error processing arguments"); cobj->setAlpha(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10533,18 +10771,18 @@ bool js_cocos2dx_studio_ColorFrame_setAlpha(JSContext *cx, uint32_t argc, jsval } 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; } @@ -10553,6 +10791,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; @@ -10564,7 +10803,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"); @@ -10573,7 +10812,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); @@ -10587,13 +10826,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; } @@ -10604,7 +10846,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; @@ -10618,8 +10860,8 @@ 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[] = { @@ -10637,7 +10879,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, @@ -10668,7 +10910,8 @@ JSObject *jsb_cocostudio_timeline_AlphaFrame_prototype; bool js_cocos2dx_studio_AlphaFrame_getAlpha(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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"); @@ -10676,7 +10919,7 @@ bool js_cocos2dx_studio_AlphaFrame_getAlpha(JSContext *cx, uint32_t argc, jsval uint16_t ret = cobj->getAlpha(); jsval jsret = JSVAL_NULL; jsret = uint32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10685,18 +10928,18 @@ bool js_cocos2dx_studio_AlphaFrame_getAlpha(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_AlphaFrame_setAlpha(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10705,6 +10948,7 @@ bool js_cocos2dx_studio_AlphaFrame_setAlpha(JSContext *cx, uint32_t argc, jsval } 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; @@ -10716,7 +10960,7 @@ bool js_cocos2dx_studio_AlphaFrame_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_AlphaFrame_create : wrong number of arguments"); @@ -10725,7 +10969,7 @@ bool js_cocos2dx_studio_AlphaFrame_create(JSContext *cx, uint32_t argc, jsval *v bool js_cocos2dx_studio_AlphaFrame_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::AlphaFrame* cobj = new (std::nothrow) cocostudio::timeline::AlphaFrame(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10739,13 +10983,16 @@ bool js_cocos2dx_studio_AlphaFrame_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::AlphaFrame"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::AlphaFrame"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -10756,7 +11003,7 @@ 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, JSObject *global) { +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; @@ -10770,8 +11017,8 @@ void js_register_cocos2dx_studio_AlphaFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_AlphaFrame_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -10787,7 +11034,7 @@ void js_register_cocos2dx_studio_AlphaFrame(JSContext *cx, JSObject *global) { jsb_cocostudio_timeline_AlphaFrame_prototype = JS_InitClass( cx, global, - jsb_cocostudio_timeline_Frame_prototype, + JS::RootedObject(cx, jsb_cocostudio_timeline_Frame_prototype), jsb_cocostudio_timeline_AlphaFrame_class, js_cocos2dx_studio_AlphaFrame_constructor, 0, // constructor properties, @@ -10818,18 +11065,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; } @@ -10838,13 +11085,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; } @@ -10853,25 +11101,25 @@ bool js_cocos2dx_studio_EventFrame_init(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_studio_EventFrame_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::EventFrame* cobj = (cocostudio::timeline::EventFrame *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_EventFrame_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_EventFrame_setNode : Error processing arguments"); cobj->setNode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10880,7 +11128,8 @@ bool js_cocos2dx_studio_EventFrame_setNode(JSContext *cx, uint32_t argc, jsval * } 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"); @@ -10888,7 +11137,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; } @@ -10897,6 +11146,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; @@ -10908,7 +11158,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"); @@ -10917,7 +11167,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); @@ -10931,13 +11181,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; } @@ -10948,7 +11201,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; @@ -10962,8 +11215,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[] = { @@ -10981,7 +11234,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, @@ -11012,7 +11265,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"); @@ -11020,7 +11274,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; } @@ -11029,18 +11283,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; } @@ -11049,6 +11303,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; @@ -11060,7 +11315,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"); @@ -11069,7 +11324,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); @@ -11083,13 +11338,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; } @@ -11100,7 +11358,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; @@ -11114,8 +11372,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[] = { @@ -11131,7 +11389,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, @@ -11162,7 +11420,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"); @@ -11177,7 +11436,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; } @@ -11186,18 +11445,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; } @@ -11206,25 +11465,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; } @@ -11233,7 +11492,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"); @@ -11248,7 +11508,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; } @@ -11257,9 +11517,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"); @@ -11267,17 +11527,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; } @@ -11286,18 +11546,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; } @@ -11306,25 +11566,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; } @@ -11333,7 +11593,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"); @@ -11341,7 +11602,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; } @@ -11350,7 +11611,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"); @@ -11358,7 +11620,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; } @@ -11367,7 +11629,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"); @@ -11382,7 +11645,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; } @@ -11391,25 +11654,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; } @@ -11418,25 +11681,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; } @@ -11445,18 +11708,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; } @@ -11465,6 +11728,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; @@ -11476,7 +11740,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"); @@ -11485,7 +11749,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); @@ -11499,13 +11763,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; } @@ -11515,7 +11782,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; @@ -11529,8 +11796,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[] = { @@ -11557,7 +11824,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, @@ -11588,18 +11855,18 @@ 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; } @@ -11608,20 +11875,20 @@ bool js_cocos2dx_studio_ActionTimelineData_setActionTag(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionTimelineData_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::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, 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_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; } @@ -11630,7 +11897,8 @@ bool js_cocos2dx_studio_ActionTimelineData_init(JSContext *cx, uint32_t argc, js } 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"); @@ -11638,7 +11906,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; } @@ -11647,11 +11915,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; @@ -11663,7 +11931,7 @@ 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"); @@ -11672,7 +11940,7 @@ bool js_cocos2dx_studio_ActionTimelineData_create(JSContext *cx, uint32_t argc, bool js_cocos2dx_studio_ActionTimelineData_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::ActionTimelineData* cobj = new (std::nothrow) cocostudio::timeline::ActionTimelineData(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11686,13 +11954,16 @@ bool js_cocos2dx_studio_ActionTimelineData_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, "cocostudio::timeline::ActionTimelineData"); + AddNamedObjectRoot(cx, &p->obj, "cocostudio::timeline::ActionTimelineData"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11702,7 +11973,7 @@ void js_cocostudio_timeline_ActionTimelineData_finalize(JSFreeOp *fop, JSObject 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; @@ -11716,8 +11987,8 @@ 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[] = { @@ -11734,7 +12005,7 @@ 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, js_cocos2dx_studio_ActionTimelineData_constructor, 0, // constructor properties, @@ -11765,18 +12036,18 @@ 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]; @@ -11788,8 +12059,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); } @@ -11804,7 +12075,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; } @@ -11813,25 +12084,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; } @@ -11840,7 +12111,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"); @@ -11848,7 +12120,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; } @@ -11857,7 +12129,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"); @@ -11865,7 +12138,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; } @@ -11874,13 +12147,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; } @@ -11889,7 +12163,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"); @@ -11897,7 +12172,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; } @@ -11906,25 +12181,25 @@ 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; } @@ -11933,13 +12208,14 @@ bool js_cocos2dx_studio_ActionTimeline_removeTimeline(JSContext *cx, uint32_t ar } bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11948,22 +12224,22 @@ bool js_cocos2dx_studio_ActionTimeline_clearFrameEventCallFunc(JSContext *cx, ui } 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 { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval rval; - bool ok = func->invoke(0, nullptr, rval); + JS::RootedValue rval(cx); + bool ok = func->invoke(0, nullptr, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -11978,7 +12254,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; } @@ -11987,7 +12263,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"); @@ -11995,7 +12272,7 @@ 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; } @@ -12004,20 +12281,20 @@ bool js_cocos2dx_studio_ActionTimeline_getTimelines(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionTimeline_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::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, 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_ActionTimeline_play : Error processing arguments"); cobj->play(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12026,20 +12303,20 @@ bool js_cocos2dx_studio_ActionTimeline_play(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_studio_ActionTimeline_getAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_getAnimationInfo : 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_ActionTimeline_getAnimationInfo : Error processing arguments"); cocostudio::timeline::AnimationInfo ret = cobj->getAnimationInfo(arg0); jsval jsret = JSVAL_NULL; jsret = animationInfo_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12048,13 +12325,14 @@ bool js_cocos2dx_studio_ActionTimeline_getAnimationInfo(JSContext *cx, uint32_t } 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; } @@ -12063,18 +12341,18 @@ bool js_cocos2dx_studio_ActionTimeline_resume(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_studio_ActionTimeline_removeAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_removeAnimationInfo : 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_ActionTimeline_removeAnimationInfo : Error processing arguments"); cobj->removeAnimationInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12083,7 +12361,8 @@ bool js_cocos2dx_studio_ActionTimeline_removeAnimationInfo(JSContext *cx, uint32 } 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"); @@ -12091,7 +12370,7 @@ 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; } @@ -12100,18 +12379,18 @@ bool js_cocos2dx_studio_ActionTimeline_getTimeSpeed(JSContext *cx, uint32_t argc } bool js_cocos2dx_studio_ActionTimeline_addAnimationInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_addAnimationInfo : Invalid Native Object"); if (argc == 1) { cocostudio::timeline::AnimationInfo arg0; - ok &= jsval_to_animationInfo(cx, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12120,7 +12399,8 @@ bool js_cocos2dx_studio_ActionTimeline_addAnimationInfo(JSContext *cx, uint32_t } 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"); @@ -12128,7 +12408,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; } @@ -12137,18 +12417,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; } @@ -12157,7 +12437,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"); @@ -12165,7 +12446,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; } @@ -12174,24 +12455,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); @@ -12199,10 +12480,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); @@ -12210,15 +12491,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); @@ -12226,18 +12507,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); @@ -12247,20 +12528,20 @@ bool js_cocos2dx_studio_ActionTimeline_gotoFrameAndPlay(JSContext *cx, uint32_t } bool js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = 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_IsAnimationInfoExists : 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_ActionTimeline_IsAnimationInfoExists : Error processing arguments"); bool ret = cobj->IsAnimationInfoExists(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12269,7 +12550,8 @@ bool js_cocos2dx_studio_ActionTimeline_IsAnimationInfoExists(JSContext *cx, uint } 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"); @@ -12277,7 +12559,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; } @@ -12286,18 +12568,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; } @@ -12306,13 +12588,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; } @@ -12321,18 +12604,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; } @@ -12341,18 +12624,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; } @@ -12361,6 +12644,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; @@ -12372,7 +12656,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"); @@ -12381,7 +12665,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); @@ -12395,13 +12679,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; } @@ -12412,7 +12699,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; @@ -12426,8 +12713,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[] = { @@ -12467,7 +12754,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, @@ -12493,61 +12780,52 @@ void js_register_cocos2dx_studio_ActionTimeline(JSContext *cx, JSObject *global) } } -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_ContourData(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_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_Skin(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_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_TextureData(cx, obj); - js_register_cocos2dx_studio_AlphaFrame(cx, obj); - js_register_cocos2dx_studio_AnimationData(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_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 a71cf82957..6d6db7cc51 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,8 +76,8 @@ 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); @@ -89,8 +89,8 @@ 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, JSObject *global); -void register_all_cocos2dx_studio(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); @@ -101,8 +101,8 @@ 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, JSObject *global); -void register_all_cocos2dx_studio(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); @@ -114,8 +114,8 @@ 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); @@ -139,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); @@ -155,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); @@ -188,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); @@ -204,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); @@ -236,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); @@ -278,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; @@ -287,8 +287,8 @@ 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); @@ -314,8 +314,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); @@ -340,8 +340,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); @@ -373,8 +373,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); @@ -389,8 +389,8 @@ 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); @@ -408,8 +408,8 @@ 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); @@ -444,8 +444,8 @@ 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); @@ -462,8 +462,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); @@ -472,8 +472,8 @@ 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); +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); @@ -484,8 +484,8 @@ 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); @@ -503,8 +503,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); @@ -515,8 +515,8 @@ 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); @@ -528,8 +528,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); @@ -540,8 +540,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); @@ -554,8 +554,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); @@ -564,8 +564,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); @@ -580,8 +580,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); @@ -595,8 +595,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); @@ -607,8 +607,8 @@ 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); @@ -627,8 +627,8 @@ 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); +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_getAlpha(JSContext *cx, uint32_t argc, jsval *vp); 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); @@ -641,8 +641,8 @@ 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, JSObject *global); -void register_all_cocos2dx_studio(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); @@ -653,8 +653,8 @@ 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_setNode(JSContext *cx, uint32_t argc, jsval *vp); @@ -667,8 +667,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); @@ -679,8 +679,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); @@ -702,8 +702,8 @@ 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); @@ -715,8 +715,8 @@ 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); 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 6105a7057f..af8c9b7a50 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, @@ -625,18 +649,18 @@ JSObject *jsb_cocos2d_ui_Widget_prototype; bool js_cocos2dx_ui_Widget_setLayoutComponentEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setLayoutComponentEnabled : 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_setLayoutComponentEnabled : Error processing arguments"); cobj->setLayoutComponentEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -645,18 +669,18 @@ bool js_cocos2dx_ui_Widget_setLayoutComponentEnabled(JSContext *cx, uint32_t arg } 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; } @@ -665,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"); @@ -673,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; } @@ -682,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"); @@ -690,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; } @@ -699,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; } @@ -719,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; } @@ -739,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"); @@ -754,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; } @@ -763,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; } @@ -783,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"); @@ -791,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; } @@ -800,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"); @@ -808,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; } @@ -817,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; } @@ -837,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; } @@ -857,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"); @@ -865,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; } @@ -874,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; } @@ -894,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; } @@ -914,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"); @@ -922,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; } @@ -931,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"); @@ -939,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; } @@ -948,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"); @@ -956,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; } @@ -965,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"); @@ -980,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; } @@ -989,18 +1023,18 @@ 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]; @@ -1013,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); } @@ -1029,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; } @@ -1038,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"); @@ -1046,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; } @@ -1055,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"); @@ -1063,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; } @@ -1072,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; } @@ -1092,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"); @@ -1121,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; } @@ -1130,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"); @@ -1138,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; } @@ -1147,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"); @@ -1155,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; } @@ -1164,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"); @@ -1172,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; } @@ -1181,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"); @@ -1189,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; } @@ -1198,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"); @@ -1206,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; } @@ -1215,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"); @@ -1223,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; } @@ -1232,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"); @@ -1240,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; } @@ -1249,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"); @@ -1257,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; } @@ -1266,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; } @@ -1286,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; } @@ -1306,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; } @@ -1326,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; } @@ -1346,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"); @@ -1354,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; } @@ -1363,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; } @@ -1383,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"); @@ -1391,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; } @@ -1400,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; } @@ -1420,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; } @@ -1447,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"); @@ -1462,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; } @@ -1471,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; } @@ -1491,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"); @@ -1499,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; } @@ -1508,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"); @@ -1516,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; } @@ -1525,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"); @@ -1535,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; } @@ -1561,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; } @@ -1581,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"); @@ -1589,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; } @@ -1598,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"); @@ -1613,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; } @@ -1622,20 +1673,20 @@ 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; } @@ -1644,7 +1695,8 @@ 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) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -1652,7 +1704,7 @@ bool js_cocos2dx_ui_Widget_isLayoutComponentEnabled(JSContext *cx, uint32_t argc bool ret = cobj->isLayoutComponentEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1661,13 +1713,14 @@ bool js_cocos2dx_ui_Widget_isLayoutComponentEnabled(JSContext *cx, uint32_t argc } 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; } @@ -1676,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); @@ -1699,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); @@ -1709,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"); @@ -1719,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; } @@ -1745,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"); @@ -1753,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; } @@ -1762,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"); @@ -1770,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; } @@ -1779,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"); @@ -1787,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; } @@ -1796,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"); @@ -1804,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; } @@ -1813,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"); @@ -1821,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; } @@ -1830,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"); @@ -1840,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; } @@ -1868,18 +1926,18 @@ 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]; @@ -1891,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); } @@ -1907,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; } @@ -1916,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"); @@ -1924,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; } @@ -1933,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"); @@ -1941,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; } @@ -1950,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; } @@ -1972,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; } @@ -1992,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"); @@ -2002,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; } @@ -2030,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; } @@ -2050,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; } @@ -2070,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"); @@ -2078,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; } @@ -2087,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"); @@ -2103,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; @@ -2114,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"); @@ -2123,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); @@ -2137,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; } @@ -2156,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; @@ -2184,8 +2249,8 @@ 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[] = { @@ -2270,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, @@ -2301,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; } @@ -2321,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; } @@ -2341,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; } @@ -2361,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; } @@ -2381,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; } @@ -2401,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"); @@ -2409,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; } @@ -2418,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"); @@ -2426,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; } @@ -2435,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"); @@ -2443,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; } @@ -2452,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; } @@ -2467,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"); @@ -2475,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; } @@ -2484,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"); @@ -2492,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; } @@ -2501,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; } @@ -2521,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; } @@ -2551,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); @@ -2577,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); @@ -2590,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; } @@ -2605,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"); @@ -2613,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; } @@ -2622,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"); @@ -2630,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; } @@ -2639,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; } @@ -2659,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"); @@ -2667,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; } @@ -2676,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"); @@ -2684,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; } @@ -2693,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"); @@ -2701,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; } @@ -2710,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"); @@ -2718,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; } @@ -2727,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; } @@ -2747,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"); @@ -2755,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; } @@ -2764,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"); @@ -2772,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; } @@ -2781,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; } @@ -2801,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"); @@ -2809,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; } @@ -2818,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; } @@ -2833,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"); @@ -2841,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; } @@ -2850,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; } @@ -2870,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"); @@ -2878,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; } @@ -2887,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; } @@ -2907,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; } @@ -2927,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; @@ -2938,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"); @@ -2947,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; @@ -2958,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"); @@ -2967,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); @@ -2981,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; } @@ -3000,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; @@ -3028,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[] = { @@ -3078,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, @@ -3109,7 +3198,8 @@ JSObject *jsb_cocos2d_ui_Button_prototype; bool js_cocos2dx_ui_Button_getNormalTextureSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -3117,7 +3207,7 @@ bool js_cocos2dx_ui_Button_getNormalTextureSize(JSContext *cx, uint32_t argc, js cocos2d::Size ret = cobj->getNormalTextureSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -3126,7 +3216,8 @@ bool js_cocos2dx_ui_Button_getNormalTextureSize(JSContext *cx, uint32_t argc, js } 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"); @@ -3134,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; } @@ -3143,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; } @@ -3163,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; } @@ -3183,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"); @@ -3198,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; } @@ -3207,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"); @@ -3215,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; } @@ -3224,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"); @@ -3232,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; } @@ -3241,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; } @@ -3261,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; } @@ -3281,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; } @@ -3301,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; } @@ -3331,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) { @@ -3378,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; } @@ -3395,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; } @@ -3415,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; } @@ -3435,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; } @@ -3465,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; } @@ -3485,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"); @@ -3493,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; } @@ -3502,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"); @@ -3510,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; } @@ -3519,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) { @@ -3552,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; } @@ -3567,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"); @@ -3575,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; } @@ -3584,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; } @@ -3614,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; } @@ -3634,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"); @@ -3642,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; } @@ -3651,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"); @@ -3659,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; } @@ -3668,7 +3767,8 @@ 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"); @@ -3676,7 +3776,7 @@ bool js_cocos2dx_ui_Button_getTitleColor(JSContext *cx, uint32_t argc, jsval *vp 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; } @@ -3685,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; } @@ -3705,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; } @@ -3725,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; @@ -3743,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; @@ -3765,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; @@ -3790,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; @@ -3818,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); @@ -3835,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); @@ -3844,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; @@ -3855,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"); @@ -3864,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); @@ -3878,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; } @@ -3897,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; @@ -3925,8 +4029,8 @@ 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[] = { @@ -3969,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, @@ -4000,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; } @@ -4030,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; } @@ -4060,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; } @@ -4080,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; } @@ -4110,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"); @@ -4118,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; } @@ -4127,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"); @@ -4139,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) { @@ -4158,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; } @@ -4177,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"); @@ -4189,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) { @@ -4206,15 +4311,15 @@ 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; } @@ -4223,7 +4328,8 @@ bool js_cocos2dx_ui_CheckBox_loadTextures(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_CheckBox_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::CheckBox* cobj = (cocos2d::ui::CheckBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_CheckBox_getZoomScale : Invalid Native Object"); @@ -4231,7 +4337,7 @@ bool js_cocos2dx_ui_CheckBox_getZoomScale(JSContext *cx, uint32_t argc, jsval *v 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; } @@ -4240,28 +4346,28 @@ bool js_cocos2dx_ui_CheckBox_getZoomScale(JSContext *cx, uint32_t argc, jsval *v } 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; } @@ -4270,18 +4376,18 @@ bool js_cocos2dx_ui_CheckBox_loadTextureBackGround(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_CheckBox_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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -4290,28 +4396,28 @@ bool js_cocos2dx_ui_CheckBox_setZoomScale(JSContext *cx, uint32_t argc, jsval *v } 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; } @@ -4320,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; @@ -4350,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; @@ -4384,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); @@ -4401,7 +4507,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); @@ -4409,10 +4515,10 @@ bool js_cocos2dx_ui_CheckBox_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::ui::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -4424,20 +4530,20 @@ 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 == 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; } cocos2d::ui::Widget::TextureResType 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::CheckBox* ret = cocos2d::ui::CheckBox::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -4449,7 +4555,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); @@ -4458,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; @@ -4469,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"); @@ -4478,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); @@ -4492,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; } @@ -4511,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; @@ -4539,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[] = { @@ -4567,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, @@ -4598,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; } @@ -4628,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; } @@ -4662,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; } @@ -4682,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; } @@ -4702,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; } @@ -4722,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"); @@ -4730,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; } @@ -4739,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"); @@ -4747,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; } @@ -4756,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; @@ -4774,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; @@ -4796,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); @@ -4813,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); @@ -4822,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; @@ -4833,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"); @@ -4842,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); @@ -4856,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; } @@ -4875,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; @@ -4903,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[] = { @@ -4927,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, @@ -4958,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; } @@ -5005,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"); @@ -5013,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; } @@ -5022,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"); @@ -5030,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; } @@ -5039,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; } @@ -5054,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"); @@ -5062,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; } @@ -5071,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; } @@ -5091,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; } @@ -5111,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; } @@ -5131,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; } @@ -5151,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"); @@ -5161,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; } @@ -5177,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"); @@ -5185,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; } @@ -5194,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"); @@ -5202,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; } @@ -5211,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; } @@ -5231,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"); @@ -5239,7 +5362,7 @@ 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; } @@ -5248,7 +5371,8 @@ 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) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -5256,7 +5380,7 @@ bool js_cocos2dx_ui_Text_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval * cocos2d::Size ret = cobj->getAutoRenderSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -5265,28 +5389,28 @@ bool js_cocos2dx_ui_Text_getAutoRenderSize(JSContext *cx, uint32_t argc, jsval * } 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; } @@ -5295,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"); @@ -5303,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; } @@ -5312,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"); @@ -5320,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; } @@ -5329,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; } @@ -5349,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; } @@ -5369,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; } @@ -5389,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"); @@ -5397,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; } @@ -5406,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"); @@ -5414,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; } @@ -5423,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; } @@ -5443,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; @@ -5467,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); @@ -5484,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); @@ -5493,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; @@ -5504,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"); @@ -5513,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); @@ -5527,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; } @@ -5546,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; @@ -5574,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[] = { @@ -5615,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, @@ -5646,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"); @@ -5654,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; } @@ -5663,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"); @@ -5671,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; } @@ -5680,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; } @@ -5700,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"); @@ -5712,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; } @@ -5728,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; } @@ -5743,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; @@ -5773,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); @@ -5790,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); @@ -5799,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; @@ -5810,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"); @@ -5819,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); @@ -5833,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; } @@ -5852,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; @@ -5880,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[] = { @@ -5902,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, @@ -5933,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; } @@ -5953,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; } @@ -5983,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; } @@ -6003,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; } @@ -6023,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; } @@ -6043,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"); @@ -6051,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; } @@ -6060,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"); @@ -6068,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; } @@ -6077,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"); @@ -6085,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; } @@ -6094,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"); @@ -6102,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; } @@ -6111,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; @@ -6129,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; @@ -6151,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); @@ -6168,7 +6311,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); @@ -6176,10 +6319,10 @@ bool js_cocos2dx_ui_LoadingBar_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::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::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -6191,20 +6334,20 @@ 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 == 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::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; } 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::ui::LoadingBar* ret = cocos2d::ui::LoadingBar::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -6216,7 +6359,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); @@ -6225,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; @@ -6236,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"); @@ -6245,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); @@ -6259,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; } @@ -6278,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; @@ -6306,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[] = { @@ -6332,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, @@ -6363,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; } @@ -6385,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"); @@ -6395,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; } @@ -6409,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"); @@ -6417,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; } @@ -6426,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"); @@ -6436,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; } @@ -6450,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"); @@ -6458,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; } @@ -6467,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; } @@ -6489,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"); @@ -6504,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; } @@ -6513,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; } @@ -6528,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; } @@ -6548,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; } @@ -6570,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; } @@ -6585,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; } @@ -6600,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; } @@ -6620,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"); @@ -6628,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; } @@ -6637,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"); @@ -6645,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; } @@ -6654,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; } @@ -6674,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; } @@ -6694,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; } @@ -6709,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; } @@ -6729,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; } @@ -6744,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; } @@ -6764,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; } @@ -6779,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; } @@ -6801,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; } @@ -6821,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"); @@ -6831,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; } @@ -6845,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; } @@ -6867,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; } @@ -6889,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; } @@ -6904,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; } @@ -6926,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; } @@ -6941,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; } @@ -6963,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; @@ -6974,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"); @@ -6983,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; @@ -6994,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"); @@ -7003,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); @@ -7017,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; } @@ -7036,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; @@ -7064,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[] = { @@ -7112,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, @@ -7143,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"); @@ -7163,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; } @@ -7172,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; } @@ -7187,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; } @@ -7207,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; } @@ -7234,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"); @@ -7242,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; } @@ -7251,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; } @@ -7271,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"); @@ -7279,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; } @@ -7288,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; } @@ -7308,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; } @@ -7323,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; } @@ -7343,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; } @@ -7358,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; } @@ -7373,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"); @@ -7381,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; } @@ -7390,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; @@ -7410,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; } @@ -7419,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; } @@ -7446,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; } @@ -7461,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; } @@ -7476,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"); @@ -7486,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; } @@ -7505,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; @@ -7516,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"); @@ -7525,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; @@ -7536,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"); @@ -7545,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); @@ -7559,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; } @@ -7578,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; @@ -7606,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[] = { @@ -7641,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, @@ -7672,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; } @@ -7692,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; } @@ -7722,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; } @@ -7752,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; } @@ -7782,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; } @@ -7812,40 +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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); 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_Slider_loadSlidBallTextures : Error processing arguments"); cobj->loadSlidBallTextures(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_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) { @@ -7853,13 +8032,13 @@ 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; } @@ -7868,18 +8047,18 @@ bool js_cocos2dx_ui_Slider_loadSlidBallTextures(JSContext *cx, uint32_t argc, js } 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; } @@ -7888,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; } @@ -7908,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"); @@ -7916,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; } @@ -7925,18 +8105,18 @@ 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; } @@ -7945,18 +8125,18 @@ bool js_cocos2dx_ui_Slider_setScale9Enabled(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Slider_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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -7965,18 +8145,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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; } @@ -7985,7 +8165,8 @@ 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) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -7993,7 +8174,7 @@ bool js_cocos2dx_ui_Slider_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; } @@ -8002,28 +8183,28 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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; } @@ -8032,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"); @@ -8040,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; } @@ -8049,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"); @@ -8057,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; } @@ -8066,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"); @@ -8074,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; } @@ -8083,16 +8267,16 @@ 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) { - 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; } cocos2d::ui::Slider* ret = cocos2d::ui::Slider::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -8104,20 +8288,20 @@ bool js_cocos2dx_ui_Slider_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; } cocos2d::ui::Widget::TextureResType 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::Slider* ret = cocos2d::ui::Slider::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -8129,7 +8313,7 @@ bool js_cocos2dx_ui_Slider_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); @@ -8146,7 +8330,7 @@ bool js_cocos2dx_ui_Slider_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); @@ -8155,6 +8339,7 @@ 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) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::Slider::createInstance(); jsval jsret = JSVAL_NULL; @@ -8166,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"); @@ -8175,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); @@ -8189,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; } @@ -8208,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; @@ -8236,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[] = { @@ -8270,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, @@ -8301,18 +8489,18 @@ JSObject *jsb_cocos2d_ui_UICCTextField_prototype; 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::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) { cocos2d::TextFieldTTF* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + 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"); @@ -8321,7 +8509,7 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME(JSContext *cx, uint32 bool ret = cobj->onTextFieldAttachWithIME(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8330,18 +8518,18 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldAttachWithIME(JSContext *cx, uint32 } bool js_cocos2dx_ui_UICCTextField_setPasswordText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8350,18 +8538,18 @@ bool js_cocos2dx_ui_UICCTextField_setPasswordText(JSContext *cx, uint32_t argc, } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setAttachWithIME : Error processing arguments"); cobj->setAttachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8370,7 +8558,8 @@ bool js_cocos2dx_ui_UICCTextField_setAttachWithIME(JSContext *cx, uint32_t argc, } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getDeleteBackward : Invalid Native Object"); @@ -8378,7 +8567,7 @@ bool js_cocos2dx_ui_UICCTextField_getDeleteBackward(JSContext *cx, uint32_t argc bool ret = cobj->getDeleteBackward(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8387,7 +8576,8 @@ bool js_cocos2dx_ui_UICCTextField_getDeleteBackward(JSContext *cx, uint32_t argc } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getAttachWithIME : Invalid Native Object"); @@ -8395,7 +8585,7 @@ bool js_cocos2dx_ui_UICCTextField_getAttachWithIME(JSContext *cx, uint32_t argc, 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; } @@ -8404,9 +8594,9 @@ bool js_cocos2dx_ui_UICCTextField_getAttachWithIME(JSContext *cx, uint32_t argc, } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward : Invalid Native Object"); @@ -8415,20 +8605,20 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward(JSContext *cx, uint3 const char* arg1; unsigned long 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::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, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); - ok &= jsval_to_ulong(cx, argv[2], &arg2); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8437,7 +8627,8 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldDeleteBackward(JSContext *cx, uint3 } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getInsertText : Invalid Native Object"); @@ -8445,7 +8636,7 @@ bool js_cocos2dx_ui_UICCTextField_getInsertText(JSContext *cx, uint32_t argc, js 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; } @@ -8454,13 +8645,14 @@ bool js_cocos2dx_ui_UICCTextField_getInsertText(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_UICCTextField_deleteBackward(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_deleteBackward : Invalid Native Object"); if (argc == 0) { cobj->deleteBackward(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8469,18 +8661,18 @@ bool js_cocos2dx_ui_UICCTextField_deleteBackward(JSContext *cx, uint32_t argc, j } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setInsertText : Error processing arguments"); cobj->setInsertText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8489,7 +8681,8 @@ bool js_cocos2dx_ui_UICCTextField_setInsertText(JSContext *cx, uint32_t argc, js } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getDetachWithIME : Invalid Native Object"); @@ -8497,7 +8690,7 @@ bool js_cocos2dx_ui_UICCTextField_getDetachWithIME(JSContext *cx, uint32_t argc, 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; } @@ -8506,7 +8699,8 @@ bool js_cocos2dx_ui_UICCTextField_getDetachWithIME(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_UICCTextField_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::ui::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_getCharCount : Invalid Native Object"); @@ -8514,7 +8708,7 @@ bool js_cocos2dx_ui_UICCTextField_getCharCount(JSContext *cx, uint32_t argc, jsv 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; } @@ -8523,13 +8717,14 @@ bool js_cocos2dx_ui_UICCTextField_getCharCount(JSContext *cx, uint32_t argc, jsv } 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::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->closeIME(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8538,18 +8733,18 @@ bool js_cocos2dx_ui_UICCTextField_closeIME(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_UICCTextField_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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setPasswordEnabled : Error processing arguments"); cobj->setPasswordEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8558,18 +8753,18 @@ bool js_cocos2dx_ui_UICCTextField_setPasswordEnabled(JSContext *cx, uint32_t arg } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled : Error processing arguments"); cobj->setMaxLengthEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8578,7 +8773,8 @@ bool js_cocos2dx_ui_UICCTextField_setMaxLengthEnabled(JSContext *cx, uint32_t ar } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_isPasswordEnabled : Invalid Native Object"); @@ -8586,7 +8782,7 @@ bool js_cocos2dx_ui_UICCTextField_isPasswordEnabled(JSContext *cx, uint32_t argc bool ret = cobj->isPasswordEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8595,20 +8791,20 @@ bool js_cocos2dx_ui_UICCTextField_isPasswordEnabled(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_UICCTextField_insertText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_ulong(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 &= 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8617,18 +8813,18 @@ bool js_cocos2dx_ui_UICCTextField_insertText(JSContext *cx, uint32_t argc, jsval } 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::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) { 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_UICCTextField_setPasswordStyleText : Error processing arguments"); cobj->setPasswordStyleText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8637,9 +8833,9 @@ bool js_cocos2dx_ui_UICCTextField_setPasswordStyleText(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_UICCTextField_onTextFieldInsertText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_onTextFieldInsertText : Invalid Native Object"); @@ -8648,20 +8844,20 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldInsertText(JSContext *cx, uint32_t const char* arg1; unsigned long 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::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, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); - ok &= jsval_to_ulong(cx, argv[2], &arg2); + 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 = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8670,18 +8866,18 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldInsertText(JSContext *cx, uint32_t } bool js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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 (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_proxy_t *jsProxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + 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"); @@ -8690,7 +8886,7 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME(JSContext *cx, uint32 bool ret = cobj->onTextFieldDetachWithIME(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8699,7 +8895,8 @@ bool js_cocos2dx_ui_UICCTextField_onTextFieldDetachWithIME(JSContext *cx, uint32 } bool js_cocos2dx_ui_UICCTextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getMaxLength : Invalid Native Object"); @@ -8707,7 +8904,7 @@ bool js_cocos2dx_ui_UICCTextField_getMaxLength(JSContext *cx, uint32_t argc, jsv int ret = cobj->getMaxLength(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -8716,7 +8913,8 @@ bool js_cocos2dx_ui_UICCTextField_getMaxLength(JSContext *cx, uint32_t argc, jsv } 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::UICCTextField* cobj = (cocos2d::ui::UICCTextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled : Invalid Native Object"); @@ -8724,7 +8922,7 @@ bool js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled(JSContext *cx, uint32_t arg 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; } @@ -8733,13 +8931,14 @@ bool js_cocos2dx_ui_UICCTextField_isMaxLengthEnabled(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_UICCTextField_openIME(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8748,18 +8947,18 @@ bool js_cocos2dx_ui_UICCTextField_openIME(JSContext *cx, uint32_t argc, jsval *v } 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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setDetachWithIME : Error processing arguments"); cobj->setDetachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8768,18 +8967,18 @@ bool js_cocos2dx_ui_UICCTextField_setDetachWithIME(JSContext *cx, uint32_t argc, } 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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8788,18 +8987,18 @@ bool js_cocos2dx_ui_UICCTextField_setMaxLength(JSContext *cx, uint32_t argc, jsv } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_UICCTextField_setDeleteBackward : Error processing arguments"); cobj->setDeleteBackward(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8808,15 +9007,15 @@ bool js_cocos2dx_ui_UICCTextField_setDeleteBackward(JSContext *cx, uint32_t argc } 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; 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_ui_UICCTextField_create : Error processing arguments"); cocos2d::ui::UICCTextField* ret = cocos2d::ui::UICCTextField::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -8828,7 +9027,7 @@ bool js_cocos2dx_ui_UICCTextField_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_UICCTextField_create : wrong number of arguments"); @@ -8837,7 +9036,7 @@ bool js_cocos2dx_ui_UICCTextField_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_ui_UICCTextField_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::UICCTextField* cobj = new (std::nothrow) cocos2d::ui::UICCTextField(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -8851,13 +9050,16 @@ bool js_cocos2dx_ui_UICCTextField_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::ui::UICCTextField"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::UICCTextField"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -8868,7 +9070,7 @@ void js_cocos2d_ui_UICCTextField_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (UICCTextField)", obj); } -void js_register_cocos2dx_ui_UICCTextField(JSContext *cx, JSObject *global) { +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; @@ -8882,8 +9084,8 @@ void js_register_cocos2dx_ui_UICCTextField(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_UICCTextField_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -8922,7 +9124,7 @@ void js_register_cocos2dx_ui_UICCTextField(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_UICCTextField_prototype = JS_InitClass( cx, global, - jsb_cocos2d_TextFieldTTF_prototype, + JS::RootedObject(cx, jsb_cocos2d_TextFieldTTF_prototype), jsb_cocos2d_ui_UICCTextField_class, js_cocos2dx_ui_UICCTextField_constructor, 0, // constructor properties, @@ -8953,18 +9155,18 @@ 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_setAttachWithIME : 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_TextField_setAttachWithIME : Error processing arguments"); cobj->setAttachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -8973,7 +9175,8 @@ bool js_cocos2dx_ui_TextField_setAttachWithIME(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_TextField_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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontSize : Invalid Native Object"); @@ -8981,7 +9184,7 @@ bool js_cocos2dx_ui_TextField_getFontSize(JSContext *cx, uint32_t argc, jsval *v 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; } @@ -8990,7 +9193,8 @@ bool js_cocos2dx_ui_TextField_getFontSize(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_TextField_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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getString : Invalid Native Object"); @@ -8998,7 +9202,7 @@ bool js_cocos2dx_ui_TextField_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; } @@ -9007,18 +9211,18 @@ bool js_cocos2dx_ui_TextField_getString(JSContext *cx, uint32_t argc, jsval *vp) } 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_setPasswordStyleText : 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_ui_TextField_setPasswordStyleText : Error processing arguments"); cobj->setPasswordStyleText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9027,7 +9231,8 @@ bool js_cocos2dx_ui_TextField_setPasswordStyleText(JSContext *cx, uint32_t argc, } 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_getDeleteBackward : Invalid Native Object"); @@ -9035,7 +9240,7 @@ bool js_cocos2dx_ui_TextField_getDeleteBackward(JSContext *cx, uint32_t argc, js bool ret = cobj->getDeleteBackward(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9044,7 +9249,8 @@ bool js_cocos2dx_ui_TextField_getDeleteBackward(JSContext *cx, uint32_t argc, js } 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_getPlaceHolder : Invalid Native Object"); @@ -9052,7 +9258,7 @@ bool js_cocos2dx_ui_TextField_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; } @@ -9061,7 +9267,8 @@ bool js_cocos2dx_ui_TextField_getPlaceHolder(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_TextField_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"); @@ -9069,7 +9276,7 @@ bool js_cocos2dx_ui_TextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsv 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; } @@ -9078,18 +9285,18 @@ bool js_cocos2dx_ui_TextField_getAttachWithIME(JSContext *cx, uint32_t argc, jsv } 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_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_TextField_setFontName : Error processing arguments"); cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9098,7 +9305,8 @@ bool js_cocos2dx_ui_TextField_setFontName(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_TextField_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"); @@ -9106,7 +9314,7 @@ bool js_cocos2dx_ui_TextField_getInsertText(JSContext *cx, uint32_t argc, jsval 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; } @@ -9115,18 +9323,18 @@ bool js_cocos2dx_ui_TextField_getInsertText(JSContext *cx, uint32_t argc, jsval } 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_setInsertText : 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_TextField_setInsertText : Error processing arguments"); cobj->setInsertText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9135,18 +9343,18 @@ bool js_cocos2dx_ui_TextField_setInsertText(JSContext *cx, uint32_t argc, jsval } 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_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_TextField_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9155,7 +9363,8 @@ bool js_cocos2dx_ui_TextField_setString(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_getDetachWithIME : Invalid Native Object"); @@ -9163,7 +9372,7 @@ bool js_cocos2dx_ui_TextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsv 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; } @@ -9172,18 +9381,18 @@ bool js_cocos2dx_ui_TextField_getDetachWithIME(JSContext *cx, uint32_t argc, jsv } 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; - 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_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_TextField_setTextVerticalAlignment : Error processing arguments"); cobj->setTextVerticalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9192,13 +9401,14 @@ bool js_cocos2dx_ui_TextField_setTextVerticalAlignment(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_TextField_didNotSelectSelf(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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) { cobj->didNotSelectSelf(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9207,7 +9417,8 @@ bool js_cocos2dx_ui_TextField_didNotSelectSelf(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_TextField_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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getFontName : Invalid Native Object"); @@ -9215,7 +9426,7 @@ bool js_cocos2dx_ui_TextField_getFontName(JSContext *cx, uint32_t argc, jsval *v 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; } @@ -9224,18 +9435,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_TextField_setTextAreaSize : Error processing arguments"); cobj->setTextAreaSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9244,13 +9455,14 @@ bool js_cocos2dx_ui_TextField_setTextAreaSize(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_TextField_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::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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9259,7 +9471,8 @@ bool js_cocos2dx_ui_TextField_attachWithIME(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_TextField_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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getStringLength : Invalid Native Object"); @@ -9267,7 +9480,7 @@ bool js_cocos2dx_ui_TextField_getStringLength(JSContext *cx, uint32_t argc, jsva 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; } @@ -9276,7 +9489,8 @@ bool js_cocos2dx_ui_TextField_getStringLength(JSContext *cx, uint32_t argc, jsva } 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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getAutoRenderSize : Invalid Native Object"); @@ -9284,7 +9498,7 @@ bool js_cocos2dx_ui_TextField_getAutoRenderSize(JSContext *cx, uint32_t argc, js cocos2d::Size ret = cobj->getAutoRenderSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9293,18 +9507,18 @@ bool js_cocos2dx_ui_TextField_getAutoRenderSize(JSContext *cx, uint32_t argc, js } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setPasswordEnabled : Error processing arguments"); cobj->setPasswordEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9313,7 +9527,8 @@ bool js_cocos2dx_ui_TextField_setPasswordEnabled(JSContext *cx, uint32_t argc, j } 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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_getPlaceHolderColor : Invalid Native Object"); @@ -9321,7 +9536,7 @@ bool js_cocos2dx_ui_TextField_getPlaceHolderColor(JSContext *cx, uint32_t argc, const cocos2d::Color4B& ret = cobj->getPlaceHolderColor(); jsval jsret = JSVAL_NULL; jsret = cccolor4b_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9330,7 +9545,8 @@ bool js_cocos2dx_ui_TextField_getPlaceHolderColor(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -9338,7 +9554,7 @@ bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, const char* ret = cobj->getPasswordStyleText(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9347,18 +9563,18 @@ bool js_cocos2dx_ui_TextField_getPasswordStyleText(JSContext *cx, uint32_t argc, } 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; - 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_setMaxLengthEnabled : 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_TextField_setMaxLengthEnabled : Error processing arguments"); cobj->setMaxLengthEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9367,7 +9583,8 @@ bool js_cocos2dx_ui_TextField_setMaxLengthEnabled(JSContext *cx, uint32_t argc, } 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::TextField* cobj = (cocos2d::ui::TextField *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextField_isPasswordEnabled : Invalid Native Object"); @@ -9375,7 +9592,7 @@ bool js_cocos2dx_ui_TextField_isPasswordEnabled(JSContext *cx, uint32_t argc, js bool ret = cobj->isPasswordEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9384,18 +9601,18 @@ bool js_cocos2dx_ui_TextField_isPasswordEnabled(JSContext *cx, uint32_t argc, js } 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDeleteBackward : Error processing arguments"); cobj->setDeleteBackward(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9404,18 +9621,18 @@ bool js_cocos2dx_ui_TextField_setDeleteBackward(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_TextField_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::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, argv[0], (int32_t *)&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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9424,18 +9641,18 @@ bool js_cocos2dx_ui_TextField_setFontSize(JSContext *cx, uint32_t argc, jsval *v } 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::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) { 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_TextField_setPlaceHolder : Error processing arguments"); cobj->setPlaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9444,22 +9661,22 @@ bool js_cocos2dx_ui_TextField_setPlaceHolder(JSContext *cx, uint32_t argc, jsval } 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 = NULL; + JS::RootedObject obj(cx); cocos2d::ui::TextField* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); 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); + ok &= jsval_to_cccolor4b(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->setPlaceHolderColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -9467,10 +9684,10 @@ bool js_cocos2dx_ui_TextField_setPlaceHolderColor(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->setPlaceHolderColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -9480,18 +9697,18 @@ bool js_cocos2dx_ui_TextField_setPlaceHolderColor(JSContext *cx, uint32_t argc, } 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::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) { 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_TextField_setTextHorizontalAlignment : Error processing arguments"); cobj->setTextHorizontalAlignment(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9500,18 +9717,18 @@ bool js_cocos2dx_ui_TextField_setTextHorizontalAlignment(JSContext *cx, uint32_t } 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::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) { 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_TextField_setTextColor : Error processing arguments"); cobj->setTextColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9520,7 +9737,8 @@ bool js_cocos2dx_ui_TextField_setTextColor(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_TextField_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -9528,7 +9746,7 @@ bool js_cocos2dx_ui_TextField_getMaxLength(JSContext *cx, uint32_t argc, jsval * int ret = cobj->getMaxLength(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9537,7 +9755,8 @@ 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) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -9545,7 +9764,7 @@ bool js_cocos2dx_ui_TextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, j 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; } @@ -9554,18 +9773,18 @@ bool js_cocos2dx_ui_TextField_isMaxLengthEnabled(JSContext *cx, uint32_t argc, j } 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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_setDetachWithIME : Error processing arguments"); cobj->setDetachWithIME(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9574,18 +9793,18 @@ bool js_cocos2dx_ui_TextField_setDetachWithIME(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_TextField_setTouchAreaEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_TextField_setTouchAreaEnabled : Error processing arguments"); cobj->setTouchAreaEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9594,20 +9813,20 @@ bool js_cocos2dx_ui_TextField_setTouchAreaEnabled(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_TextField_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::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); + ok &= jsval_to_vector2(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_TextField_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; } @@ -9616,18 +9835,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_TextField_setMaxLength : Error processing arguments"); cobj->setMaxLength(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9636,18 +9855,18 @@ bool js_cocos2dx_ui_TextField_setMaxLength(JSContext *cx, uint32_t argc, jsval * } 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::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::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_TextField_setTouchSize : Error processing arguments"); cobj->setTouchSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9656,7 +9875,8 @@ bool js_cocos2dx_ui_TextField_setTouchSize(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -9664,7 +9884,7 @@ bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval * cocos2d::Size ret = cobj->getTouchSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -9673,19 +9893,19 @@ bool js_cocos2dx_ui_TextField_getTouchSize(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_TextField_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::TextField* ret = cocos2d::ui::TextField::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -9697,7 +9917,7 @@ bool js_cocos2dx_ui_TextField_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); @@ -9714,7 +9934,7 @@ bool js_cocos2dx_ui_TextField_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); @@ -9723,6 +9943,7 @@ bool js_cocos2dx_ui_TextField_create(JSContext *cx, uint32_t argc, jsval *vp) } 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::TextField::createInstance(); jsval jsret = JSVAL_NULL; @@ -9734,7 +9955,7 @@ bool js_cocos2dx_ui_TextField_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_TextField_createInstance : wrong number of arguments"); @@ -9743,7 +9964,7 @@ bool js_cocos2dx_ui_TextField_createInstance(JSContext *cx, uint32_t argc, jsval 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::TextField* cobj = new (std::nothrow) cocos2d::ui::TextField(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -9757,13 +9978,16 @@ bool js_cocos2dx_ui_TextField_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::TextField"); + 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; } @@ -9776,21 +10000,21 @@ void js_cocos2d_ui_TextField_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::TextField"); + 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_TextField(JSContext *cx, JSObject *global) { +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; @@ -9804,8 +10028,8 @@ void js_register_cocos2dx_ui_TextField(JSContext *cx, JSObject *global) { 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[] = { @@ -9859,7 +10083,7 @@ void js_register_cocos2dx_ui_TextField(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_TextField_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_TextField_class, js_cocos2dx_ui_TextField_constructor, 0, // constructor properties, @@ -9890,18 +10114,18 @@ JSObject *jsb_cocos2d_ui_TextBMFont_prototype; 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; - 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_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_ui_TextBMFont_setFntFile : Error processing arguments"); cobj->setFntFile(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9910,7 +10134,8 @@ bool js_cocos2dx_ui_TextBMFont_setFntFile(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_TextBMFont_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::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getStringLength : Invalid Native Object"); @@ -9918,7 +10143,7 @@ bool js_cocos2dx_ui_TextBMFont_getStringLength(JSContext *cx, uint32_t argc, jsv 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; } @@ -9927,18 +10152,18 @@ bool js_cocos2dx_ui_TextBMFont_getStringLength(JSContext *cx, uint32_t argc, jsv } 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; - 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"); 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_TextBMFont_setString : Error processing arguments"); cobj->setString(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -9947,7 +10172,8 @@ bool js_cocos2dx_ui_TextBMFont_setString(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_TextBMFont_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::TextBMFont* cobj = (cocos2d::ui::TextBMFont *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_TextBMFont_getString : Invalid Native Object"); @@ -9955,7 +10181,7 @@ bool js_cocos2dx_ui_TextBMFont_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; } @@ -9964,16 +10190,16 @@ bool js_cocos2dx_ui_TextBMFont_getString(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; 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::TextBMFont* ret = cocos2d::ui::TextBMFont::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -9985,7 +10211,7 @@ bool js_cocos2dx_ui_TextBMFont_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); @@ -10002,7 +10228,7 @@ bool js_cocos2dx_ui_TextBMFont_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); @@ -10011,6 +10237,7 @@ bool js_cocos2dx_ui_TextBMFont_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_TextBMFont_createInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::Ref* ret = cocos2d::ui::TextBMFont::createInstance(); jsval jsret = JSVAL_NULL; @@ -10022,7 +10249,7 @@ bool js_cocos2dx_ui_TextBMFont_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_TextBMFont_createInstance : wrong number of arguments"); @@ -10031,7 +10258,7 @@ bool js_cocos2dx_ui_TextBMFont_createInstance(JSContext *cx, uint32_t argc, jsva 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; cocos2d::ui::TextBMFont* cobj = new (std::nothrow) cocos2d::ui::TextBMFont(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10045,13 +10272,16 @@ bool js_cocos2dx_ui_TextBMFont_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::TextBMFont"); + 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; } @@ -10064,21 +10294,21 @@ void js_cocos2d_ui_TextBMFont_finalize(JSFreeOp *fop, JSObject *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); + 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::TextBMFont"); + 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_TextBMFont(JSContext *cx, JSObject *global) { +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; @@ -10092,8 +10322,8 @@ void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JSObject *global) { 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[] = { @@ -10113,7 +10343,7 @@ void js_register_cocos2dx_ui_TextBMFont(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_TextBMFont_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_TextBMFont_class, js_cocos2dx_ui_TextBMFont_constructor, 0, // constructor properties, @@ -10144,7 +10374,8 @@ 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::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_getCustomScrollThreshold : Invalid Native Object"); @@ -10152,7 +10383,7 @@ bool js_cocos2dx_ui_PageView_getCustomScrollThreshold(JSContext *cx, uint32_t ar double ret = cobj->getCustomScrollThreshold(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10161,7 +10392,8 @@ bool js_cocos2dx_ui_PageView_getCustomScrollThreshold(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -10169,7 +10401,7 @@ bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval ssize_t ret = cobj->getCurPageIndex(); jsval jsret = JSVAL_NULL; jsret = ssize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10178,9 +10410,9 @@ bool js_cocos2dx_ui_PageView_getCurPageIndex(JSContext *cx, uint32_t argc, jsval } 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; - 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"); @@ -10189,18 +10421,18 @@ bool js_cocos2dx_ui_PageView_addWidgetToPage(JSContext *cx, uint32_t argc, jsval ssize_t 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::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])); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10209,7 +10441,8 @@ bool js_cocos2dx_ui_PageView_addWidgetToPage(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -10217,7 +10450,7 @@ bool js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(JSContext *cx, uint32_ bool ret = cobj->isUsingCustomScrollThreshold(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10226,15 +10459,15 @@ bool js_cocos2dx_ui_PageView_isUsingCustomScrollThreshold(JSContext *cx, uint32_ } 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::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, argv[0], &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; @@ -10246,7 +10479,7 @@ bool js_cocos2dx_ui_PageView_getPage(JSContext *cx, uint32_t argc, jsval *vp) jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10255,25 +10488,25 @@ bool js_cocos2dx_ui_PageView_getPage(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; - 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_removePage : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Layout* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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::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); + args.rval().setUndefined(); return true; } @@ -10282,18 +10515,18 @@ bool js_cocos2dx_ui_PageView_removePage(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; - 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"); 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_PageView_setUsingCustomScrollThreshold : Error processing arguments"); cobj->setUsingCustomScrollThreshold(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10302,18 +10535,18 @@ bool js_cocos2dx_ui_PageView_setUsingCustomScrollThreshold(JSContext *cx, uint32 } bool js_cocos2dx_ui_PageView_setCustomScrollThreshold(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_PageView_setCustomScrollThreshold : Error processing arguments"); cobj->setCustomScrollThreshold(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10322,9 +10555,9 @@ bool js_cocos2dx_ui_PageView_setCustomScrollThreshold(JSContext *cx, uint32_t ar } 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::PageView* cobj = (cocos2d::ui::PageView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_PageView_insertPage : Invalid Native Object"); @@ -10332,17 +10565,17 @@ bool js_cocos2dx_ui_PageView_insertPage(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::ui::Layout* 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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10351,18 +10584,18 @@ bool js_cocos2dx_ui_PageView_insertPage(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_PageView_scrollToPage(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_scrollToPage : 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_PageView_scrollToPage : Error processing arguments"); cobj->scrollToPage(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10371,18 +10604,18 @@ bool js_cocos2dx_ui_PageView_scrollToPage(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_PageView_removePageAtIndex(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_PageView_removePageAtIndex : Error processing arguments"); cobj->removePageAtIndex(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10391,7 +10624,8 @@ bool js_cocos2dx_ui_PageView_removePageAtIndex(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_PageView_getPages(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -10399,7 +10633,7 @@ bool js_cocos2dx_ui_PageView_getPages(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::Vector& ret = cobj->getPages(); jsval jsret = JSVAL_NULL; jsret = ccvector_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10408,13 +10642,14 @@ bool js_cocos2dx_ui_PageView_getPages(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_PageView_removeAllPages(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -10423,25 +10658,25 @@ bool js_cocos2dx_ui_PageView_removeAllPages(JSContext *cx, uint32_t argc, jsval } 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; - 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"); if (argc == 1) { cocos2d::ui::Layout* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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::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); + args.rval().setUndefined(); return true; } @@ -10450,6 +10685,7 @@ bool js_cocos2dx_ui_PageView_addPage(JSContext *cx, uint32_t argc, jsval *vp) } 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; @@ -10461,7 +10697,7 @@ bool js_cocos2dx_ui_PageView_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_PageView_create : wrong number of arguments"); @@ -10470,6 +10706,7 @@ bool js_cocos2dx_ui_PageView_create(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; @@ -10481,7 +10718,7 @@ 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"); @@ -10490,7 +10727,7 @@ bool js_cocos2dx_ui_PageView_createInstance(JSContext *cx, uint32_t argc, jsval 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::PageView* cobj = new (std::nothrow) cocos2d::ui::PageView(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10504,13 +10741,16 @@ bool js_cocos2dx_ui_PageView_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::PageView"); + 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; } @@ -10523,21 +10763,21 @@ void js_cocos2d_ui_PageView_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::PageView"); + 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_PageView(JSContext *cx, JSObject *global) { +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; @@ -10551,8 +10791,8 @@ void js_register_cocos2dx_ui_PageView(JSContext *cx, JSObject *global) { 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[] = { @@ -10582,7 +10822,7 @@ void js_register_cocos2dx_ui_PageView(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_PageView_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), jsb_cocos2d_ui_PageView_class, js_cocos2dx_ui_PageView_constructor, 0, // constructor properties, @@ -10613,20 +10853,20 @@ JSObject *jsb_cocos2d_ui_Helper_prototype; 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; if (argc == 3) { 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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Helper_getSubStringOfUTF8String : wrong number of arguments"); @@ -10635,14 +10875,14 @@ bool js_cocos2dx_ui_Helper_getSubStringOfUTF8String(JSContext *cx, uint32_t argc 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; 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_Helper_changeLayoutSystemActiveState : Error processing arguments"); cocos2d::ui::Helper::changeLayoutSystemActiveState(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Helper_changeLayoutSystemActiveState : wrong number of arguments"); @@ -10651,20 +10891,20 @@ bool js_cocos2dx_ui_Helper_changeLayoutSystemActiveState(JSContext *cx, uint32_t 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; 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::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); + 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; @@ -10676,7 +10916,7 @@ bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(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_ui_Helper_seekActionWidgetByActionTag : wrong number of arguments"); @@ -10685,20 +10925,20 @@ bool js_cocos2dx_ui_Helper_seekActionWidgetByActionTag(JSContext *cx, uint32_t a 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; if (argc == 2) { cocos2d::ui::Widget* 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::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); + 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; @@ -10710,7 +10950,7 @@ bool js_cocos2dx_ui_Helper_seekWidgetByName(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_Helper_seekWidgetByName : wrong number of arguments"); @@ -10719,20 +10959,20 @@ bool js_cocos2dx_ui_Helper_seekWidgetByName(JSContext *cx, uint32_t argc, jsval 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; 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::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); + 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; @@ -10744,7 +10984,7 @@ bool js_cocos2dx_ui_Helper_seekWidgetByTag(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_Helper_seekWidgetByTag : wrong number of arguments"); @@ -10753,18 +10993,18 @@ bool js_cocos2dx_ui_Helper_seekWidgetByTag(JSContext *cx, uint32_t argc, jsval * 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; if (argc == 2) { cocos2d::Rect arg0; cocos2d::Size arg1; - ok &= jsval_to_ccrect(cx, argv[0], &arg0); - ok &= jsval_to_ccsize(cx, argv[1], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Helper_restrictCapInsetRect : wrong number of arguments"); @@ -10773,21 +11013,21 @@ bool js_cocos2dx_ui_Helper_restrictCapInsetRect(JSContext *cx, uint32_t argc, js bool js_cocos2dx_ui_Helper_doLayout(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"); } 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); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_ui_Helper_doLayout : wrong number of arguments"); @@ -10800,7 +11040,7 @@ 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) { +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; @@ -10814,8 +11054,8 @@ void js_register_cocos2dx_ui_Helper(JSContext *cx, JSObject *global) { 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[] = { @@ -10835,7 +11075,7 @@ void js_register_cocos2dx_ui_Helper(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Helper_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_ui_Helper_class, empty_constructor, 0, properties, @@ -10866,9 +11106,9 @@ 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); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::RichElement* cobj = (cocos2d::ui::RichElement *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElement_init : Invalid Native Object"); @@ -10876,14 +11116,14 @@ bool js_cocos2dx_ui_RichElement_init(JSContext *cx, uint32_t argc, jsval *vp) 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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -10892,7 +11132,7 @@ bool js_cocos2dx_ui_RichElement_init(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::RichElement* cobj = new (std::nothrow) cocos2d::ui::RichElement(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -10906,13 +11146,16 @@ bool js_cocos2dx_ui_RichElement_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::RichElement"); + 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; } @@ -10924,21 +11167,21 @@ void js_cocos2d_ui_RichElement_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::RichElement"); + 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_RichElement(JSContext *cx, JSObject *global) { +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; @@ -10952,8 +11195,8 @@ void js_register_cocos2dx_ui_RichElement(JSContext *cx, JSObject *global) { 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[] = { @@ -10966,7 +11209,7 @@ void js_register_cocos2dx_ui_RichElement(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RichElement_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_ui_RichElement_class, js_cocos2dx_ui_RichElement_constructor, 0, // constructor properties, @@ -10997,9 +11240,9 @@ JSObject *jsb_cocos2d_ui_RichElementText_prototype; 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::RichElementText* cobj = (cocos2d::ui::RichElementText *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementText_init : Invalid Native Object"); @@ -11010,17 +11253,17 @@ bool js_cocos2dx_ui_RichElementText_init(JSContext *cx, uint32_t argc, jsval *vp 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); + 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; } @@ -11029,7 +11272,7 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; if (argc == 6) { int arg0; @@ -11038,12 +11281,12 @@ bool js_cocos2dx_ui_RichElementText_create(JSContext *cx, uint32_t argc, jsval * 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); + 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; @@ -11055,7 +11298,7 @@ bool js_cocos2dx_ui_RichElementText_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_RichElementText_create : wrong number of arguments"); @@ -11064,7 +11307,7 @@ bool js_cocos2dx_ui_RichElementText_create(JSContext *cx, uint32_t argc, jsval * 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::RichElementText* cobj = new (std::nothrow) cocos2d::ui::RichElementText(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11078,13 +11321,16 @@ bool js_cocos2dx_ui_RichElementText_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::RichElementText"); + 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; } @@ -11097,21 +11343,21 @@ void js_cocos2d_ui_RichElementText_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::RichElementText"); + 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_RichElementText(JSContext *cx, JSObject *global) { +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; @@ -11125,8 +11371,8 @@ void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JSObject *global) { 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[] = { @@ -11142,7 +11388,7 @@ void js_register_cocos2dx_ui_RichElementText(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RichElementText_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_RichElement_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), jsb_cocos2d_ui_RichElementText_class, js_cocos2dx_ui_RichElementText_constructor, 0, // constructor properties, @@ -11173,9 +11419,9 @@ JSObject *jsb_cocos2d_ui_RichElementImage_prototype; 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::RichElementImage* cobj = (cocos2d::ui::RichElementImage *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementImage_init : Invalid Native Object"); @@ -11184,15 +11430,15 @@ bool js_cocos2dx_ui_RichElementImage_init(JSContext *cx, uint32_t argc, jsval *v 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); + 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; } @@ -11201,17 +11447,17 @@ bool js_cocos2dx_ui_RichElementImage_init(JSContext *cx, uint32_t argc, jsval *v } 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; 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); + 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; @@ -11223,7 +11469,7 @@ bool js_cocos2dx_ui_RichElementImage_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_RichElementImage_create : wrong number of arguments"); @@ -11232,7 +11478,7 @@ bool js_cocos2dx_ui_RichElementImage_create(JSContext *cx, uint32_t argc, jsval 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::RichElementImage* cobj = new (std::nothrow) cocos2d::ui::RichElementImage(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11246,13 +11492,16 @@ bool js_cocos2dx_ui_RichElementImage_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::ui::RichElementImage"); + 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; } @@ -11265,21 +11514,21 @@ void js_cocos2d_ui_RichElementImage_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::RichElementImage"); + 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_RichElementImage(JSContext *cx, JSObject *global) { +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; @@ -11293,8 +11542,8 @@ void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JSObject *global) { 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[] = { @@ -11310,7 +11559,7 @@ void js_register_cocos2dx_ui_RichElementImage(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RichElementImage_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_RichElement_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), jsb_cocos2d_ui_RichElementImage_class, js_cocos2dx_ui_RichElementImage_constructor, 0, // constructor properties, @@ -11341,9 +11590,9 @@ JSObject *jsb_cocos2d_ui_RichElementCustomNode_prototype; bool js_cocos2dx_ui_RichElementCustomNode_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::RichElementCustomNode* cobj = (cocos2d::ui::RichElementCustomNode *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichElementCustomNode_init : Invalid Native Object"); @@ -11352,13 +11601,13 @@ bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsv 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); + 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 (!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::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -11367,7 +11616,7 @@ bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsv 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; } @@ -11376,20 +11625,20 @@ bool js_cocos2dx_ui_RichElementCustomNode_init(JSContext *cx, uint32_t argc, jsv } 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; 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); + 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 (!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::Node*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -11405,7 +11654,7 @@ bool js_cocos2dx_ui_RichElementCustomNode_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_RichElementCustomNode_create : wrong number of arguments"); @@ -11414,7 +11663,7 @@ bool js_cocos2dx_ui_RichElementCustomNode_create(JSContext *cx, uint32_t argc, j 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; cocos2d::ui::RichElementCustomNode* cobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11428,13 +11677,16 @@ bool js_cocos2dx_ui_RichElementCustomNode_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::RichElementCustomNode"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichElementCustomNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11447,21 +11699,21 @@ void js_cocos2d_ui_RichElementCustomNode_finalize(JSFreeOp *fop, JSObject *obj) static bool js_cocos2d_ui_RichElementCustomNode_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::RichElementCustomNode *nobj = new (std::nothrow) cocos2d::ui::RichElementCustomNode(); 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::RichElementCustomNode"); 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) { +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; @@ -11475,8 +11727,8 @@ void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JSObject *glob jsb_cocos2d_ui_RichElementCustomNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {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 +11744,7 @@ void js_register_cocos2dx_ui_RichElementCustomNode(JSContext *cx, JSObject *glob jsb_cocos2d_ui_RichElementCustomNode_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_RichElement_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_RichElement_prototype), jsb_cocos2d_ui_RichElementCustomNode_class, js_cocos2dx_ui_RichElementCustomNode_constructor, 0, // constructor properties, @@ -11523,9 +11775,9 @@ 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::RichText* cobj = (cocos2d::ui::RichText *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_RichText_insertElement : Invalid Native Object"); @@ -11533,17 +11785,17 @@ bool js_cocos2dx_ui_RichText_insertElement(JSContext *cx, uint32_t argc, jsval * cocos2d::ui::RichElement* 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); 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_ui_RichText_insertElement : Error processing arguments"); cobj->insertElement(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11552,18 +11804,18 @@ bool js_cocos2dx_ui_RichText_insertElement(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_RichText_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); 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); + ok &= jsval_to_vector2(cx, args.get(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); + args.rval().setUndefined(); return true; } @@ -11572,25 +11824,25 @@ bool js_cocos2dx_ui_RichText_setAnchorPoint(JSContext *cx, uint32_t argc, jsval } 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::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; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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); 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); + args.rval().setUndefined(); return true; } @@ -11599,18 +11851,18 @@ bool js_cocos2dx_ui_RichText_pushBackElement(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_RichText_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize : Error processing arguments"); cobj->ignoreContentAdaptWithSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11619,18 +11871,18 @@ bool js_cocos2dx_ui_RichText_ignoreContentAdaptWithSize(JSContext *cx, uint32_t } bool js_cocos2dx_ui_RichText_setVerticalSpace(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -11639,13 +11891,14 @@ bool js_cocos2dx_ui_RichText_setVerticalSpace(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_RichText_formatText(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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::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); + args.rval().setUndefined(); return true; } @@ -11654,12 +11907,12 @@ 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) { - 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::RichText* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); 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"); @@ -11667,16 +11920,16 @@ bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval * if (argc == 1) { cocos2d::ui::RichElement* arg0; do { - if (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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); 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); + args.rval().setUndefined(); return true; } } while(0); @@ -11684,10 +11937,10 @@ bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval * 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->removeElement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -11697,6 +11950,7 @@ bool js_cocos2dx_ui_RichText_removeElement(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_RichText_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::RichText* ret = cocos2d::ui::RichText::create(); jsval jsret = JSVAL_NULL; @@ -11708,7 +11962,7 @@ bool js_cocos2dx_ui_RichText_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_RichText_create : wrong number of arguments"); @@ -11717,7 +11971,7 @@ bool js_cocos2dx_ui_RichText_create(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; cocos2d::ui::RichText* cobj = new (std::nothrow) cocos2d::ui::RichText(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -11731,13 +11985,16 @@ bool js_cocos2dx_ui_RichText_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::RichText"); + 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); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11750,21 +12007,21 @@ void js_cocos2d_ui_RichText_finalize(JSFreeOp *fop, JSObject *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); + 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); - JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RichText"); + 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); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + args.rval().setUndefined(); return true; } -void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global) { +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; @@ -11778,8 +12035,8 @@ void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RichText_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11801,7 +12058,7 @@ void js_register_cocos2dx_ui_RichText(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RichText_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_RichText_class, js_cocos2dx_ui_RichText_constructor, 0, // constructor properties, @@ -11832,20 +12089,20 @@ JSObject *jsb_cocos2d_ui_HBox_prototype; bool js_cocos2dx_ui_HBox_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::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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -11854,13 +12111,13 @@ 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) { - 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::ui::HBox* ret = cocos2d::ui::HBox::create(arg0); jsval jsret = JSVAL_NULL; @@ -11872,7 +12129,7 @@ bool js_cocos2dx_ui_HBox_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); @@ -11889,7 +12146,7 @@ bool js_cocos2dx_ui_HBox_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); @@ -11898,7 +12155,7 @@ bool js_cocos2dx_ui_HBox_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_HBox_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::Ref *_ccobj = dynamic_cast(cobj); @@ -11912,13 +12169,16 @@ bool js_cocos2dx_ui_HBox_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::HBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::HBox"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -11931,21 +12191,21 @@ void js_cocos2d_ui_HBox_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_HBox_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::HBox *nobj = new (std::nothrow) cocos2d::ui::HBox(); 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::HBox"); 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) { +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; @@ -11959,8 +12219,8 @@ void js_register_cocos2dx_ui_HBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_HBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -11976,7 +12236,7 @@ void js_register_cocos2dx_ui_HBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_HBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), jsb_cocos2d_ui_HBox_class, js_cocos2dx_ui_HBox_constructor, 0, // constructor properties, @@ -12007,20 +12267,20 @@ JSObject *jsb_cocos2d_ui_VBox_prototype; bool js_cocos2dx_ui_VBox_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::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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12029,13 +12289,13 @@ 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) { - 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::ui::VBox* ret = cocos2d::ui::VBox::create(arg0); jsval jsret = JSVAL_NULL; @@ -12047,7 +12307,7 @@ bool js_cocos2dx_ui_VBox_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); @@ -12064,7 +12324,7 @@ bool js_cocos2dx_ui_VBox_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); @@ -12073,7 +12333,7 @@ bool js_cocos2dx_ui_VBox_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_VBox_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::Ref *_ccobj = dynamic_cast(cobj); @@ -12087,13 +12347,16 @@ bool js_cocos2dx_ui_VBox_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::VBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::VBox"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -12106,21 +12369,21 @@ void js_cocos2d_ui_VBox_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_VBox_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::VBox *nobj = new (std::nothrow) cocos2d::ui::VBox(); 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::VBox"); 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) { +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; @@ -12134,8 +12397,8 @@ void js_register_cocos2dx_ui_VBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_VBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -12151,7 +12414,7 @@ void js_register_cocos2dx_ui_VBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_VBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), jsb_cocos2d_ui_VBox_class, js_cocos2dx_ui_VBox_constructor, 0, // constructor properties, @@ -12182,20 +12445,20 @@ JSObject *jsb_cocos2d_ui_RelativeBox_prototype; bool js_cocos2dx_ui_RelativeBox_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::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); + 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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12204,13 +12467,13 @@ bool js_cocos2dx_ui_RelativeBox_initWithSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_RelativeBox_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::ui::RelativeBox* ret = cocos2d::ui::RelativeBox::create(arg0); jsval jsret = JSVAL_NULL; @@ -12222,7 +12485,7 @@ bool js_cocos2dx_ui_RelativeBox_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); @@ -12239,7 +12502,7 @@ bool js_cocos2dx_ui_RelativeBox_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); @@ -12248,7 +12511,7 @@ bool js_cocos2dx_ui_RelativeBox_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_RelativeBox_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::Ref *_ccobj = dynamic_cast(cobj); @@ -12262,13 +12525,16 @@ bool js_cocos2dx_ui_RelativeBox_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::RelativeBox"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::RelativeBox"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -12281,21 +12547,21 @@ void js_cocos2d_ui_RelativeBox_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_RelativeBox_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::RelativeBox *nobj = new (std::nothrow) cocos2d::ui::RelativeBox(); 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::RelativeBox"); 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) { +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; @@ -12309,8 +12575,8 @@ void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RelativeBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -12326,7 +12592,7 @@ void js_register_cocos2dx_ui_RelativeBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_RelativeBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Layout_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Layout_prototype), jsb_cocos2d_ui_RelativeBox_class, js_cocos2dx_ui_RelativeBox_constructor, 0, // constructor properties, @@ -12357,13 +12623,14 @@ JSObject *jsb_cocos2d_ui_Scale9Sprite_prototype; bool js_cocos2dx_ui_Scale9Sprite_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::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); + args.rval().setUndefined(); return true; } @@ -12372,12 +12639,12 @@ bool js_cocos2dx_ui_Scale9Sprite_disableCascadeColor(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *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::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -12385,32 +12652,32 @@ bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, 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"); } 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; } cocos2d::Rect arg5; - ok &= jsval_to_ccrect(cx, argv[5], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12419,26 +12686,26 @@ bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, 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"); } 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::Rect arg3; - ok &= jsval_to_ccrect(cx, argv[3], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12448,7 +12715,8 @@ bool js_cocos2dx_ui_Scale9Sprite_updateWithSprite(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Scale9Sprite_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::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedX : Invalid Native Object"); @@ -12456,7 +12724,7 @@ bool js_cocos2dx_ui_Scale9Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval 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; } @@ -12465,18 +12733,18 @@ bool js_cocos2dx_ui_Scale9Sprite_isFlippedX(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setScale9Enabled : Error processing arguments"); cobj->setScale9Enabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12485,18 +12753,18 @@ bool js_cocos2dx_ui_Scale9Sprite_setScale9Enabled(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Scale9Sprite_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedY : Error processing arguments"); cobj->setFlippedY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12505,18 +12773,18 @@ bool js_cocos2dx_ui_Scale9Sprite_setFlippedY(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_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::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])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_Scale9Sprite_setFlippedX : Error processing arguments"); cobj->setFlippedX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12525,15 +12793,15 @@ bool js_cocos2dx_ui_Scale9Sprite_setFlippedX(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_resizableSpriteWithCapInsets : 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_Scale9Sprite_resizableSpriteWithCapInsets : Error processing arguments"); cocos2d::ui::Scale9Sprite* ret = cobj->resizableSpriteWithCapInsets(arg0); jsval jsret = JSVAL_NULL; @@ -12545,7 +12813,7 @@ bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uin jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12554,13 +12822,14 @@ bool js_cocos2dx_ui_Scale9Sprite_resizableSpriteWithCapInsets(JSContext *cx, uin } bool js_cocos2dx_ui_Scale9Sprite_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::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); + args.rval().setUndefined(); return true; } @@ -12569,18 +12838,18 @@ bool js_cocos2dx_ui_Scale9Sprite_disableCascadeOpacity(JSContext *cx, uint32_t a } bool js_cocos2dx_ui_Scale9Sprite_setState(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setState : Invalid Native Object"); if (argc == 1) { cocos2d::ui::Scale9Sprite::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_ui_Scale9Sprite_setState : Error processing arguments"); cobj->setState(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12589,18 +12858,18 @@ bool js_cocos2dx_ui_Scale9Sprite_setState(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_Scale9Sprite_setInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setInsetBottom : 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_Scale9Sprite_setInsetBottom : Error processing arguments"); cobj->setInsetBottom(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12609,24 +12878,24 @@ bool js_cocos2dx_ui_Scale9Sprite_setInsetBottom(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(JSContext *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::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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, argv[0], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12634,15 +12903,15 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(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; } 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->initWithSpriteFrameName(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); @@ -12652,7 +12921,8 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrameName(JSContext *cx, uint32_t } bool js_cocos2dx_ui_Scale9Sprite_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::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getSprite : Invalid Native Object"); @@ -12667,7 +12937,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getSprite(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12676,18 +12946,18 @@ bool js_cocos2dx_ui_Scale9Sprite_getSprite(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_Scale9Sprite_setInsetTop(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setInsetTop : 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_Scale9Sprite_setInsetTop : Error processing arguments"); cobj->setInsetTop(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12696,12 +12966,12 @@ bool js_cocos2dx_ui_Scale9Sprite_setInsetTop(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_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); cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -12709,26 +12979,26 @@ bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) 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"); } 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::Rect arg3; - ok &= jsval_to_ccrect(cx, argv[3], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12738,7 +13008,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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; } } while(0); @@ -12747,24 +13017,24 @@ bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) 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"); } 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::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12773,32 +13043,32 @@ bool js_cocos2dx_ui_Scale9Sprite_init(JSContext *cx, uint32_t argc, jsval *vp) 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"); } 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; } cocos2d::Rect arg5; - ok &= jsval_to_ccrect(cx, argv[5], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -12808,18 +13078,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_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_ui_Scale9Sprite_setPreferredSize : Error processing arguments"); cobj->setPreferredSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12828,42 +13098,42 @@ bool js_cocos2dx_ui_Scale9Sprite_setPreferredSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Scale9Sprite_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::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 (!argv[0].isObject()) { ok = false; break; } + if (!args.get(0).isObject()) { ok = false; break; } js_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_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); cobj->setSpriteFrame(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { cocos2d::SpriteFrame* 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::SpriteFrame*)(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_ui_Scale9Sprite_setSpriteFrame : Error processing arguments"); cobj->setSpriteFrame(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -12872,7 +13142,8 @@ bool js_cocos2dx_ui_Scale9Sprite_setSpriteFrame(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -12880,7 +13151,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, js double ret = cobj->getInsetBottom(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12889,7 +13160,8 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetBottom(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_Scale9Sprite_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::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getCapInsets : Invalid Native Object"); @@ -12897,7 +13169,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getCapInsets(JSContext *cx, uint32_t argc, jsva 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; } @@ -12906,7 +13178,8 @@ bool js_cocos2dx_ui_Scale9Sprite_getCapInsets(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Scale9Sprite_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::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isScale9Enabled : Invalid Native Object"); @@ -12914,7 +13187,7 @@ bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, j 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; } @@ -12923,7 +13196,8 @@ bool js_cocos2dx_ui_Scale9Sprite_isScale9Enabled(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -12931,7 +13205,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsv double ret = cobj->getInsetRight(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -12940,7 +13214,8 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetRight(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Scale9Sprite_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::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getOriginalSize : Invalid Native Object"); @@ -12948,7 +13223,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getOriginalSize(JSContext *cx, uint32_t argc, j 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; } @@ -12957,27 +13232,27 @@ bool js_cocos2dx_ui_Scale9Sprite_getOriginalSize(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_Scale9Sprite_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::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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, 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); @@ -12985,18 +13260,18 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsva 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::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::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &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); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while(0); @@ -13004,15 +13279,15 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsva do { if (argc == 2) { 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; } 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->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); @@ -13020,12 +13295,12 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsva 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); @@ -13035,7 +13310,8 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithFile(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -13043,7 +13319,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval double ret = cobj->getInsetTop(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13052,18 +13328,18 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetTop(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_setInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13072,12 +13348,12 @@ bool js_cocos2dx_ui_Scale9Sprite_setInsetLeft(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Scale9Sprite_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 = NULL; + JS::RootedObject obj(cx); cocos2d::ui::Scale9Sprite* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -13085,9 +13361,9 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t arg 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"); @@ -13096,7 +13372,7 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t arg 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; } } while(0); @@ -13105,21 +13381,21 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t arg 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::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); + ok &= jsval_to_ccrect(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } 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); @@ -13129,7 +13405,8 @@ bool js_cocos2dx_ui_Scale9Sprite_initWithSpriteFrame(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_Scale9Sprite_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::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_getPreferredSize : Invalid Native Object"); @@ -13137,7 +13414,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getPreferredSize(JSContext *cx, uint32_t argc, 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; } @@ -13146,18 +13423,18 @@ bool js_cocos2dx_ui_Scale9Sprite_getPreferredSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_Scale9Sprite_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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13166,7 +13443,8 @@ bool js_cocos2dx_ui_Scale9Sprite_setCapInsets(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Scale9Sprite_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::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_Scale9Sprite_isFlippedY : Invalid Native Object"); @@ -13174,7 +13452,7 @@ bool js_cocos2dx_ui_Scale9Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval 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; } @@ -13183,7 +13461,8 @@ bool js_cocos2dx_ui_Scale9Sprite_isFlippedY(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_Scale9Sprite_getInsetLeft(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -13191,7 +13470,7 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetLeft(JSContext *cx, uint32_t argc, jsva double ret = cobj->getInsetLeft(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13200,18 +13479,18 @@ bool js_cocos2dx_ui_Scale9Sprite_getInsetLeft(JSContext *cx, uint32_t argc, jsva } bool js_cocos2dx_ui_Scale9Sprite_setInsetRight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13220,19 +13499,19 @@ bool js_cocos2dx_ui_Scale9Sprite_setInsetRight(JSContext *cx, uint32_t argc, jsv } bool js_cocos2dx_ui_Scale9Sprite_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; } 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::Rect arg2; - ok &= jsval_to_ccrect(cx, argv[2], &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; @@ -13244,7 +13523,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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); @@ -13261,7 +13540,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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); @@ -13269,10 +13548,10 @@ bool js_cocos2dx_ui_Scale9Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { 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; } 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); jsval jsret = JSVAL_NULL; @@ -13284,7 +13563,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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); @@ -13292,10 +13571,10 @@ bool js_cocos2dx_ui_Scale9Sprite_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::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -13307,7 +13586,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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); @@ -13315,7 +13594,7 @@ bool js_cocos2dx_ui_Scale9Sprite_create(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::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::create(arg0); jsval jsret = JSVAL_NULL; @@ -13327,7 +13606,7 @@ bool js_cocos2dx_ui_Scale9Sprite_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); @@ -13336,16 +13615,16 @@ bool js_cocos2dx_ui_Scale9Sprite_create(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(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; } 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::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -13357,7 +13636,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13365,7 +13644,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(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; } cocos2d::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrameName(arg0); jsval jsret = JSVAL_NULL; @@ -13377,7 +13656,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(JSContext *cx, uint32 jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13386,23 +13665,23 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrameName(JSContext *cx, uint32 } bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(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::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; } 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::ui::Scale9Sprite* ret = cocos2d::ui::Scale9Sprite::createWithSpriteFrame(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -13414,7 +13693,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13423,9 +13702,9 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t a 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"); @@ -13441,7 +13720,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } } while (0); @@ -13450,7 +13729,7 @@ bool js_cocos2dx_ui_Scale9Sprite_createWithSpriteFrame(JSContext *cx, uint32_t a } 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; cocos2d::ui::Scale9Sprite* cobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -13464,13 +13743,16 @@ bool js_cocos2dx_ui_Scale9Sprite_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::Scale9Sprite"); + AddNamedObjectRoot(cx, &p->obj, "cocos2d::ui::Scale9Sprite"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; } @@ -13483,21 +13765,21 @@ void js_cocos2d_ui_Scale9Sprite_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_cocos2d_ui_Scale9Sprite_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::Scale9Sprite *nobj = new (std::nothrow) cocos2d::ui::Scale9Sprite(); 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::Scale9Sprite"); 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) { +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; @@ -13511,8 +13793,8 @@ void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JSObject *global) { 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} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -13559,7 +13841,7 @@ void js_register_cocos2dx_ui_Scale9Sprite(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_Scale9Sprite_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Node_prototype, + JS::RootedObject(cx, jsb_cocos2d_Node_prototype), jsb_cocos2d_ui_Scale9Sprite_class, js_cocos2dx_ui_Scale9Sprite_constructor, 0, // constructor properties, @@ -13590,7 +13872,8 @@ 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::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getText : Invalid Native Object"); @@ -13598,7 +13881,7 @@ bool js_cocos2dx_ui_EditBox_getText(JSContext *cx, uint32_t argc, jsval *vp) const char* ret = cobj->getText(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13607,18 +13890,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_EditBox_setFontSize : Error processing arguments"); cobj->setFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13627,18 +13910,18 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_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(); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13647,7 +13930,8 @@ bool js_cocos2dx_ui_EditBox_setPlaceholderFontName(JSContext *cx, uint32_t argc, } 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::EditBox* cobj = (cocos2d::ui::EditBox *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_EditBox_getPlaceHolder : Invalid Native Object"); @@ -13655,7 +13939,7 @@ bool js_cocos2dx_ui_EditBox_getPlaceHolder(JSContext *cx, uint32_t argc, jsval * const char* ret = cobj->getPlaceHolder(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13664,18 +13948,18 @@ bool js_cocos2dx_ui_EditBox_getPlaceHolder(JSContext *cx, uint32_t argc, jsval * } bool js_cocos2dx_ui_EditBox_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::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, 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_ui_EditBox_setFontName : Error processing arguments"); cobj->setFontName(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13684,18 +13968,18 @@ bool js_cocos2dx_ui_EditBox_setFontName(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_EditBox_setText(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_ui_EditBox_setText : Error processing arguments"); cobj->setText(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13704,18 +13988,18 @@ bool js_cocos2dx_ui_EditBox_setText(JSContext *cx, uint32_t argc, jsval *vp) } bool js_cocos2dx_ui_EditBox_setPlaceholderFontSize(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_EditBox_setPlaceholderFontSize : Error processing arguments"); cobj->setPlaceholderFontSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13724,18 +14008,18 @@ bool js_cocos2dx_ui_EditBox_setPlaceholderFontSize(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_EditBox_setInputMode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); if (argc == 1) { cocos2d::ui::EditBox::InputMode 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_EditBox_setInputMode : Error processing arguments"); cobj->setInputMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13744,18 +14028,18 @@ bool js_cocos2dx_ui_EditBox_setInputMode(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 = 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"); 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_EditBox_setPlaceholderFontColor : Error processing arguments"); cobj->setPlaceholderFontColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13764,18 +14048,18 @@ bool js_cocos2dx_ui_EditBox_setPlaceholderFontColor(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_EditBox_setFontColor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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"); 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_EditBox_setFontColor : Error processing arguments"); cobj->setFontColor(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13784,20 +14068,20 @@ bool js_cocos2dx_ui_EditBox_setFontColor(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::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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13806,25 +14090,25 @@ bool js_cocos2dx_ui_EditBox_setPlaceholderFont(JSContext *cx, uint32_t argc, jsv } 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; + JS::RootedObject obj(cx); cocos2d::ui::EditBox* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + 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_initWithSizeAndBackgroundSprite : Invalid Native Object"); 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::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"); @@ -13833,7 +14117,7 @@ bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint3 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); @@ -13841,15 +14125,15 @@ bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint3 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; } 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->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); @@ -13857,18 +14141,18 @@ bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint3 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; } 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::Widget::TextureResType 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->initWithSizeAndBackgroundSprite(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); @@ -13878,18 +14162,18 @@ bool js_cocos2dx_ui_EditBox_initWithSizeAndBackgroundSprite(JSContext *cx, uint3 } bool js_cocos2dx_ui_EditBox_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::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, 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_ui_EditBox_setPlaceHolder : Error processing arguments"); cobj->setPlaceHolder(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13898,18 +14182,18 @@ bool js_cocos2dx_ui_EditBox_setPlaceHolder(JSContext *cx, uint32_t argc, jsval * } 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::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::ui::EditBox::KeyboardReturnType 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_EditBox_setReturnType : Error processing arguments"); cobj->setReturnType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13918,18 +14202,18 @@ bool js_cocos2dx_ui_EditBox_setReturnType(JSContext *cx, uint32_t argc, jsval *v } bool js_cocos2dx_ui_EditBox_setInputFlag(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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_setInputFlag : Invalid Native Object"); if (argc == 1) { cocos2d::ui::EditBox::InputFlag 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_EditBox_setInputFlag : Error processing arguments"); cobj->setInputFlag(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13938,7 +14222,8 @@ bool js_cocos2dx_ui_EditBox_setInputFlag(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_EditBox_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -13946,7 +14231,7 @@ bool js_cocos2dx_ui_EditBox_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp int ret = cobj->getMaxLength(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -13955,18 +14240,18 @@ bool js_cocos2dx_ui_EditBox_getMaxLength(JSContext *cx, uint32_t argc, jsval *vp } bool js_cocos2dx_ui_EditBox_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::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, argv[0], (int32_t *)&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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13975,20 +14260,20 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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); + 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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -13997,16 +14282,16 @@ 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) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; 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; } 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::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1); jsval jsret = JSVAL_NULL; @@ -14018,20 +14303,20 @@ bool js_cocos2dx_ui_EditBox_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::Size arg0; - ok &= jsval_to_ccsize(cx, argv[0], &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::Widget::TextureResType 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::EditBox* ret = cocos2d::ui::EditBox::create(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; @@ -14043,7 +14328,7 @@ bool js_cocos2dx_ui_EditBox_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); @@ -14051,13 +14336,13 @@ bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) 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::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"); @@ -14073,20 +14358,20 @@ bool js_cocos2dx_ui_EditBox_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::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::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"); @@ -14094,9 +14379,9 @@ bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cocos2d::ui::Scale9Sprite* 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::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -14112,20 +14397,20 @@ bool js_cocos2dx_ui_EditBox_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) { 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::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"); @@ -14133,9 +14418,9 @@ bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cocos2d::ui::Scale9Sprite* 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::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); @@ -14143,9 +14428,9 @@ bool js_cocos2dx_ui_EditBox_create(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cocos2d::ui::Scale9Sprite* 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::ui::Scale9Sprite*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2( arg3, cx, false, "Invalid Native Object"); @@ -14161,7 +14446,7 @@ bool js_cocos2dx_ui_EditBox_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); @@ -14170,7 +14455,7 @@ bool js_cocos2dx_ui_EditBox_create(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::EditBox* cobj = new (std::nothrow) cocos2d::ui::EditBox(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -14184,13 +14469,16 @@ bool js_cocos2dx_ui_EditBox_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::EditBox"); + 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; } @@ -14203,21 +14491,21 @@ void js_cocos2d_ui_EditBox_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::EditBox"); + 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_EditBox(JSContext *cx, JSObject *global) { +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; @@ -14231,8 +14519,8 @@ void js_register_cocos2dx_ui_EditBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_EditBox_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -14265,7 +14553,7 @@ void js_register_cocos2dx_ui_EditBox(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_EditBox_prototype = JS_InitClass( cx, global, - jsb_cocos2d_ui_Widget_prototype, + JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype), jsb_cocos2d_ui_EditBox_class, js_cocos2dx_ui_EditBox_constructor, 0, // constructor properties, @@ -14296,18 +14584,18 @@ JSObject *jsb_cocos2d_ui_LayoutComponent_prototype; bool js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled : Error processing arguments"); cobj->setStretchWidthEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14316,18 +14604,18 @@ bool js_cocos2dx_ui_LayoutComponent_setStretchWidthEnabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_LayoutComponent_setPercentWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14336,7 +14624,8 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentWidth(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_LayoutComponent_getAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14344,7 +14633,7 @@ bool js_cocos2dx_ui_LayoutComponent_getAnchorPosition(JSContext *cx, uint32_t ar const cocos2d::Point& ret = cobj->getAnchorPosition(); jsval jsret = JSVAL_NULL; jsret = ccpoint_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14353,18 +14642,18 @@ bool js_cocos2dx_ui_LayoutComponent_getAnchorPosition(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled : Error processing arguments"); cobj->setPositionPercentXEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14373,18 +14662,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPositionPercentXEnabled(JSContext *cx, ui } bool js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled : Error processing arguments"); cobj->setStretchHeightEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14393,18 +14682,18 @@ bool js_cocos2dx_ui_LayoutComponent_setStretchHeightEnabled(JSContext *cx, uint3 } bool js_cocos2dx_ui_LayoutComponent_setActiveEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setActiveEnabled : Error processing arguments"); cobj->setActiveEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14413,7 +14702,8 @@ bool js_cocos2dx_ui_LayoutComponent_setActiveEnabled(JSContext *cx, uint32_t arg } bool js_cocos2dx_ui_LayoutComponent_getRightMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14421,7 +14711,7 @@ bool js_cocos2dx_ui_LayoutComponent_getRightMargin(JSContext *cx, uint32_t argc, double ret = cobj->getRightMargin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14430,7 +14720,8 @@ bool js_cocos2dx_ui_LayoutComponent_getRightMargin(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_getSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14438,7 +14729,7 @@ bool js_cocos2dx_ui_LayoutComponent_getSize(JSContext *cx, uint32_t argc, jsval const cocos2d::Size& ret = cobj->getSize(); jsval jsret = JSVAL_NULL; jsret = ccsize_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14447,18 +14738,18 @@ bool js_cocos2dx_ui_LayoutComponent_getSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LayoutComponent_setAnchorPosition(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14467,13 +14758,14 @@ bool js_cocos2dx_ui_LayoutComponent_setAnchorPosition(JSContext *cx, uint32_t ar } bool js_cocos2dx_ui_LayoutComponent_refreshLayout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14482,7 +14774,8 @@ bool js_cocos2dx_ui_LayoutComponent_refreshLayout(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14490,7 +14783,7 @@ bool js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled(JSContext *cx, uint32_ bool ret = cobj->isPercentWidthEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14499,18 +14792,18 @@ bool js_cocos2dx_ui_LayoutComponent_isPercentWidthEnabled(JSContext *cx, uint32_ } bool js_cocos2dx_ui_LayoutComponent_setVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, argv[0], (int32_t *)&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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14519,7 +14812,8 @@ bool js_cocos2dx_ui_LayoutComponent_setVerticalEdge(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_LayoutComponent_getTopMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14527,7 +14821,7 @@ bool js_cocos2dx_ui_LayoutComponent_getTopMargin(JSContext *cx, uint32_t argc, j double ret = cobj->getTopMargin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14536,18 +14830,18 @@ bool js_cocos2dx_ui_LayoutComponent_getTopMargin(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_LayoutComponent_setSizeWidth(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14556,7 +14850,8 @@ bool js_cocos2dx_ui_LayoutComponent_setSizeWidth(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_LayoutComponent_getPercentContentSize(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14564,7 +14859,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentContentSize(JSContext *cx, uint32_ cocos2d::Vec2 ret = cobj->getPercentContentSize(); jsval jsret = JSVAL_NULL; jsret = vector2_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14573,7 +14868,8 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentContentSize(JSContext *cx, uint32_ } bool js_cocos2dx_ui_LayoutComponent_getVerticalEdge(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14581,7 +14877,7 @@ bool js_cocos2dx_ui_LayoutComponent_getVerticalEdge(JSContext *cx, uint32_t argc int ret = (int)cobj->getVerticalEdge(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14590,18 +14886,18 @@ bool js_cocos2dx_ui_LayoutComponent_getVerticalEdge(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled : Error processing arguments"); cobj->setPercentWidthEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14610,7 +14906,8 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentWidthEnabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14618,7 +14915,7 @@ bool js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled(JSContext *cx, uint32_ bool ret = cobj->isStretchWidthEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14627,18 +14924,18 @@ bool js_cocos2dx_ui_LayoutComponent_isStretchWidthEnabled(JSContext *cx, uint32_ } bool js_cocos2dx_ui_LayoutComponent_setLeftMargin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14647,7 +14944,8 @@ bool js_cocos2dx_ui_LayoutComponent_setLeftMargin(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_getSizeWidth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14655,7 +14953,7 @@ bool js_cocos2dx_ui_LayoutComponent_getSizeWidth(JSContext *cx, uint32_t argc, j double ret = cobj->getSizeWidth(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14664,18 +14962,18 @@ bool js_cocos2dx_ui_LayoutComponent_getSizeWidth(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled : Error processing arguments"); cobj->setPositionPercentYEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14684,7 +14982,8 @@ bool js_cocos2dx_ui_LayoutComponent_setPositionPercentYEnabled(JSContext *cx, ui } bool js_cocos2dx_ui_LayoutComponent_getSizeHeight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14692,7 +14991,7 @@ bool js_cocos2dx_ui_LayoutComponent_getSizeHeight(JSContext *cx, uint32_t argc, double ret = cobj->getSizeHeight(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14701,7 +15000,8 @@ bool js_cocos2dx_ui_LayoutComponent_getSizeHeight(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_getPositionPercentY(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14709,7 +15009,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPositionPercentY(JSContext *cx, uint32_t double ret = cobj->getPositionPercentY(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14718,7 +15018,8 @@ bool js_cocos2dx_ui_LayoutComponent_getPositionPercentY(JSContext *cx, uint32_t } 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::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPositionPercentX : Invalid Native Object"); @@ -14726,7 +15027,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPositionPercentX(JSContext *cx, uint32_t double ret = cobj->getPositionPercentX(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14735,18 +15036,18 @@ bool js_cocos2dx_ui_LayoutComponent_getPositionPercentX(JSContext *cx, uint32_t } 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::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) { 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_LayoutComponent_setTopMargin : Error processing arguments"); cobj->setTopMargin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14755,7 +15056,8 @@ bool js_cocos2dx_ui_LayoutComponent_setTopMargin(JSContext *cx, uint32_t argc, j } bool js_cocos2dx_ui_LayoutComponent_getPercentHeight(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getPercentHeight : Invalid Native Object"); @@ -14763,7 +15065,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentHeight(JSContext *cx, uint32_t arg double ret = cobj->getPercentHeight(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14772,7 +15074,8 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentHeight(JSContext *cx, uint32_t arg } 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::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize : Invalid Native Object"); @@ -14780,7 +15083,7 @@ bool js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize(JSContext *cx, ui bool ret = cobj->getUsingPercentContentSize(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14789,18 +15092,18 @@ bool js_cocos2dx_ui_LayoutComponent_getUsingPercentContentSize(JSContext *cx, ui } 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::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) { 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_LayoutComponent_setPositionPercentY : Error processing arguments"); cobj->setPositionPercentY(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14809,18 +15112,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPositionPercentY(JSContext *cx, uint32_t } 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::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) { 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_LayoutComponent_setPositionPercentX : Error processing arguments"); cobj->setPositionPercentX(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14829,18 +15132,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPositionPercentX(JSContext *cx, uint32_t } 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::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) { 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_LayoutComponent_setRightMargin : Error processing arguments"); cobj->setRightMargin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14849,7 +15152,8 @@ bool js_cocos2dx_ui_LayoutComponent_setRightMargin(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -14857,7 +15161,7 @@ bool js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled(JSContext *cx, uin bool ret = cobj->isPositionPercentYEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14866,18 +15170,18 @@ bool js_cocos2dx_ui_LayoutComponent_isPositionPercentYEnabled(JSContext *cx, uin } 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::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) { 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_LayoutComponent_setPercentHeight : Error processing arguments"); cobj->setPercentHeight(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14886,18 +15190,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentHeight(JSContext *cx, uint32_t arg } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled : Error processing arguments"); cobj->setPercentOnlyEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14906,18 +15210,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentOnlyEnabled(JSContext *cx, uint32_ } 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::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::ui::LayoutComponent::HorizontalEdge 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_LayoutComponent_setHorizontalEdge : Error processing arguments"); cobj->setHorizontalEdge(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14926,18 +15230,18 @@ bool js_cocos2dx_ui_LayoutComponent_setHorizontalEdge(JSContext *cx, uint32_t ar } 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14946,18 +15250,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPosition(JSContext *cx, uint32_t argc, js } 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; - 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::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(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize : Error processing arguments"); cobj->setUsingPercentContentSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -14966,7 +15270,8 @@ bool js_cocos2dx_ui_LayoutComponent_setUsingPercentContentSize(JSContext *cx, ui } bool js_cocos2dx_ui_LayoutComponent_getLeftMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getLeftMargin : Invalid Native Object"); @@ -14974,7 +15279,7 @@ bool js_cocos2dx_ui_LayoutComponent_getLeftMargin(JSContext *cx, uint32_t argc, double ret = cobj->getLeftMargin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -14983,7 +15288,8 @@ bool js_cocos2dx_ui_LayoutComponent_getLeftMargin(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_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::ui::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_getPosition : Invalid Native Object"); @@ -14991,7 +15297,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPosition(JSContext *cx, uint32_t argc, js const 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; } @@ -15000,18 +15306,18 @@ bool js_cocos2dx_ui_LayoutComponent_getPosition(JSContext *cx, uint32_t argc, js } bool js_cocos2dx_ui_LayoutComponent_setSizeHeight(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - 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::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, JS::RootedValue(cx, argv[0]), &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -15020,7 +15326,8 @@ bool js_cocos2dx_ui_LayoutComponent_setSizeHeight(JSContext *cx, uint32_t argc, } bool js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -15028,7 +15335,7 @@ bool js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled(JSContext *cx, uin bool ret = cobj->isPositionPercentXEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15037,7 +15344,8 @@ bool js_cocos2dx_ui_LayoutComponent_isPositionPercentXEnabled(JSContext *cx, uin } bool js_cocos2dx_ui_LayoutComponent_getBottomMargin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -15045,7 +15353,7 @@ bool js_cocos2dx_ui_LayoutComponent_getBottomMargin(JSContext *cx, uint32_t argc double ret = cobj->getBottomMargin(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15054,18 +15362,18 @@ bool js_cocos2dx_ui_LayoutComponent_getBottomMargin(JSContext *cx, uint32_t argc } 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::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) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(args.get(0)); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled : Error processing arguments"); cobj->setPercentHeightEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -15074,18 +15382,18 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentHeightEnabled(JSContext *cx, uint3 } 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::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::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_LayoutComponent_setPercentContentSize : Error processing arguments"); cobj->setPercentContentSize(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -15094,7 +15402,8 @@ bool js_cocos2dx_ui_LayoutComponent_setPercentContentSize(JSContext *cx, uint32_ } bool js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -15102,7 +15411,7 @@ bool js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled(JSContext *cx, uint32 bool ret = cobj->isPercentHeightEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15111,7 +15420,8 @@ bool js_cocos2dx_ui_LayoutComponent_isPercentHeightEnabled(JSContext *cx, uint32 } bool js_cocos2dx_ui_LayoutComponent_getPercentWidth(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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"); @@ -15119,7 +15429,7 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentWidth(JSContext *cx, uint32_t argc double ret = cobj->getPercentWidth(); jsval jsret = JSVAL_NULL; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15128,7 +15438,8 @@ bool js_cocos2dx_ui_LayoutComponent_getPercentWidth(JSContext *cx, uint32_t argc } bool js_cocos2dx_ui_LayoutComponent_getHorizontalEdge(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + 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_getHorizontalEdge : Invalid Native Object"); @@ -15136,7 +15447,7 @@ bool js_cocos2dx_ui_LayoutComponent_getHorizontalEdge(JSContext *cx, uint32_t ar int ret = (int)cobj->getHorizontalEdge(); jsval jsret = JSVAL_NULL; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15145,7 +15456,8 @@ bool js_cocos2dx_ui_LayoutComponent_getHorizontalEdge(JSContext *cx, uint32_t ar } 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::LayoutComponent* cobj = (cocos2d::ui::LayoutComponent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled : Invalid Native Object"); @@ -15153,7 +15465,7 @@ bool js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled(JSContext *cx, uint32 bool ret = cobj->isStretchHeightEnabled(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -15162,18 +15474,18 @@ bool js_cocos2dx_ui_LayoutComponent_isStretchHeightEnabled(JSContext *cx, uint32 } 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::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) { 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_LayoutComponent_setBottomMargin : Error processing arguments"); cobj->setBottomMargin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -15182,18 +15494,18 @@ bool js_cocos2dx_ui_LayoutComponent_setBottomMargin(JSContext *cx, uint32_t argc } 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::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, argv[0], &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); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -15202,6 +15514,7 @@ bool js_cocos2dx_ui_LayoutComponent_setSize(JSContext *cx, uint32_t argc, jsval } bool js_cocos2dx_ui_LayoutComponent_create(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::ui::LayoutComponent* ret = cocos2d::ui::LayoutComponent::create(); jsval jsret = JSVAL_NULL; @@ -15213,7 +15526,7 @@ bool js_cocos2dx_ui_LayoutComponent_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_LayoutComponent_create : wrong number of arguments"); @@ -15222,14 +15535,14 @@ bool js_cocos2dx_ui_LayoutComponent_create(JSContext *cx, uint32_t argc, jsval * bool js_cocos2dx_ui_LayoutComponent_bindLayoutComponent(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"); @@ -15245,7 +15558,7 @@ bool js_cocos2dx_ui_LayoutComponent_bindLayoutComponent(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_ui_LayoutComponent_bindLayoutComponent : wrong number of arguments"); @@ -15254,7 +15567,7 @@ bool js_cocos2dx_ui_LayoutComponent_bindLayoutComponent(JSContext *cx, uint32_t 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::LayoutComponent* cobj = new (std::nothrow) cocos2d::ui::LayoutComponent(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); @@ -15268,13 +15581,16 @@ bool js_cocos2dx_ui_LayoutComponent_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::LayoutComponent"); + 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; } @@ -15287,21 +15603,21 @@ void js_cocos2d_ui_LayoutComponent_finalize(JSFreeOp *fop, JSObject *obj) { 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); + 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::LayoutComponent"); + 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_LayoutComponent(JSContext *cx, JSObject *global) { +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; @@ -15315,8 +15631,8 @@ void js_register_cocos2dx_ui_LayoutComponent(JSContext *cx, JSObject *global) { 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[] = { @@ -15381,7 +15697,7 @@ void js_register_cocos2dx_ui_LayoutComponent(JSContext *cx, JSObject *global) { jsb_cocos2d_ui_LayoutComponent_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Component_prototype, + JS::RootedObject(cx, jsb_cocos2d_Component_prototype), jsb_cocos2d_ui_LayoutComponent_class, js_cocos2dx_ui_LayoutComponent_constructor, 0, // constructor properties, @@ -15407,49 +15723,40 @@ void js_register_cocos2dx_ui_LayoutComponent(JSContext *cx, JSObject *global) { } } -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_RichText(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_LayoutComponent(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_RichElementImage(cx, obj); - js_register_cocos2dx_ui_RelativeLayoutParameter(cx, obj); - js_register_cocos2dx_ui_UICCTextField(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 0354c40b2e..b8010d3824 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,8 @@ 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); @@ -132,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); @@ -176,8 +176,8 @@ 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); @@ -214,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); @@ -236,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); @@ -254,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); @@ -289,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); @@ -305,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); @@ -325,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); @@ -367,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); @@ -396,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); @@ -424,8 +424,8 @@ 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, JSObject *global); -void register_all_cocos2dx_ui(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); @@ -459,8 +459,8 @@ 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); @@ -508,8 +508,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); @@ -523,8 +523,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); @@ -548,8 +548,8 @@ 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); @@ -563,8 +563,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); @@ -573,8 +573,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); @@ -584,8 +584,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); @@ -595,8 +595,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); @@ -606,8 +606,8 @@ 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); @@ -623,8 +623,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); @@ -634,8 +634,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); @@ -645,8 +645,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); @@ -656,8 +656,8 @@ 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); @@ -698,8 +698,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); @@ -726,8 +726,8 @@ 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, JSObject *global); -void register_all_cocos2dx_ui(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); 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..2f1e79615b --- /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, "cc", &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 746b4024ca..7c37f79d27 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) #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) closesocket(fd); #else close(fd); @@ -121,19 +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 || func.isPrimitive()) { 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 || thisObj.isPrimitive()) { - JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval); + if (thisObj.isNullOrUndefined()) { + JS_CallFunctionValue(cx, obj, func, dataVal, retval); } else { - 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); } } @@ -207,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) @@ -224,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); +// } } } @@ -280,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 @@ -291,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; }; @@ -306,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; }; @@ -324,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.. @@ -343,12 +349,13 @@ 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"); #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; }; @@ -360,13 +367,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; }; @@ -374,28 +382,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); @@ -423,18 +438,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) @@ -449,31 +473,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); } } @@ -482,21 +500,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() @@ -512,7 +519,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); } @@ -524,11 +531,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; } @@ -539,12 +556,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 @@ -553,35 +570,46 @@ 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); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + _global.emplace(_cx); +#else + _global.construct(_cx); +#endif + _global.ref() = NewGlobalObject(_cx); + + JSAutoCompartment ac(_cx, _global.ref()); + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) + // Removed in Firefox v34 + js::SetDefaultObjectForContext(_cx, _global.ref()); +#endif 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()); } } @@ -623,7 +651,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; @@ -643,7 +671,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); } } @@ -654,19 +682,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; } } @@ -702,19 +733,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) { @@ -722,6 +782,7 @@ bool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* cx) JS_ReportPendingException(cx); } } +#endif return evaluatedOK; } @@ -784,14 +845,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; } @@ -805,7 +867,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); } } @@ -818,16 +880,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 { @@ -835,11 +897,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; } @@ -871,12 +934,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; @@ -885,9 +948,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; } @@ -896,7 +960,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; @@ -910,7 +975,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; @@ -922,7 +988,8 @@ 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; @@ -931,15 +998,15 @@ void ScriptingCore::cleanupSchedulesAndActions(js_proxy_t* p) 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; } @@ -963,12 +1030,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); } @@ -976,7 +1043,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); } @@ -984,14 +1051,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); } @@ -1019,12 +1086,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); } @@ -1032,7 +1099,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); } @@ -1040,7 +1107,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); } @@ -1049,7 +1116,13 @@ int ScriptingCore::handleComponentEvent(void* data) return 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::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, JS::MutableHandleValue jsvalRet) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -1057,15 +1130,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; } @@ -1080,20 +1153,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) { @@ -1105,7 +1171,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 @@ -1121,27 +1193,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); @@ -1150,7 +1222,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 @@ -1165,27 +1243,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); @@ -1198,26 +1276,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 { @@ -1230,14 +1330,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; @@ -1299,25 +1394,24 @@ bool ScriptingCore::handleFocusEvent(void* nativeObj, cocos2d::ui::Widget* widge 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) { @@ -1333,7 +1427,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); @@ -1350,7 +1444,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 @@ -1358,7 +1452,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); @@ -1379,7 +1473,7 @@ int ScriptingCore::sendEvent(ScriptEvent* evt) return 0; } - JSAutoCompartment ac(_cx, _global); + JSAutoCompartment ac(_cx, _global.ref().get()); switch (evt->type) { @@ -1420,7 +1514,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 @@ -1446,13 +1540,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() @@ -1499,26 +1593,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; } @@ -1562,7 +1662,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) WSADATA wsaData; err = WSAStartup(MAKEWORD(2, 2),&wsaData); #endif @@ -1643,8 +1743,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); @@ -1654,32 +1754,40 @@ bool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp) void ScriptingCore::enableDebugger(unsigned int port) { - if (_debugGlobal == NULL) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + if (_debugGlobal.isNothing()) +#else + if (_debugGlobal.empty()) +#endif { - JSAutoCompartment ac0(_cx, _global); + JSAutoCompartment ac0(_cx, _global.ref().get()); JS_SetDebugMode(_cx, true); - - _debugGlobal = NewGlobalObject(_cx, true); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + _debugGlobal.emplace(_cx); +#else + _debugGlobal.construct(_cx); +#endif + _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); } @@ -1687,7 +1795,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); } @@ -1698,7 +1806,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 bc0cd2e517..ab28bf6766 100644 --- a/frameworks/js-bindings/bindings/manual/ScriptingCore.h +++ b/frameworks/js-bindings/bindings/manual/ScriptingCore.h @@ -34,17 +34,18 @@ #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.3" +#define ENGINE_VERSION "Cocos2d-JS v3.4 Beta0" 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 @@ -58,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; @@ -118,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 @@ -147,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 @@ -191,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, @@ -241,22 +250,28 @@ 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); 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 94d221b618..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); @@ -748,12 +735,12 @@ jsval cpVect_to_jsval( JSContext *cx, cpVect p) #ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES - 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, "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) ) + 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); @@ -778,11 +765,11 @@ 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 @@ -814,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 ); @@ -823,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; @@ -840,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 ); @@ -849,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; @@ -867,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 ); @@ -876,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"); } @@ -889,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 ); @@ -898,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 @@ -925,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 */ @@ -962,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"); @@ -988,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; @@ -1021,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; } @@ -1031,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); @@ -1047,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) @@ -1068,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; @@ -1097,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 ); } @@ -1114,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; } @@ -1136,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"); @@ -1151,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; } @@ -1172,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"); @@ -1186,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 @@ -1206,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; } @@ -1233,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; } @@ -1260,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; } @@ -1287,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; } @@ -1316,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; } @@ -1339,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; } @@ -1362,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; } @@ -1385,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; } @@ -1406,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(); @@ -1424,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; } @@ -1443,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(); @@ -1470,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; } @@ -1496,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); } } @@ -1510,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; @@ -1545,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); } } @@ -1562,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; @@ -1598,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); } } @@ -1615,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; @@ -1652,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; @@ -1689,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); } } @@ -1704,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); @@ -1725,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); @@ -1746,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); @@ -1768,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); } @@ -1783,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; @@ -1811,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); } } @@ -1826,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); @@ -1847,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); @@ -1868,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); @@ -1886,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; @@ -1895,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; } @@ -1916,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 @@ -1936,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; @@ -1951,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; } @@ -1972,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 @@ -1990,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 @@ -2002,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; @@ -2026,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; } @@ -2046,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 @@ -2063,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); } @@ -2080,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; } @@ -2090,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); } @@ -2106,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 @@ -2116,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; } @@ -2136,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"); @@ -2152,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; } @@ -2160,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; } @@ -2196,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; } @@ -2228,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; } @@ -2242,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; @@ -2271,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), @@ -2282,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); } @@ -2292,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); @@ -2335,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 bd21452434..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 @@ -96,11 +96,11 @@ 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 0665a3e619..d76e89c55e 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,7 +629,7 @@ 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"); @@ -626,7 +638,7 @@ bool js_cocos2dx_CCMenuItemToggle_create(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_MenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) { - 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); @@ -635,21 +647,30 @@ bool js_cocos2dx_MenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1 || argc == 2) { std::function arg0; do { - if(JS_TypeOfValue(cx, argv[0]) == JSTYPE_FUNCTION) + if(JS_TypeOfValue(cx, args[0]) == JSTYPE_FUNCTION) { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + 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); - jsval rval; - bool ok = func->invoke(1, &largv[0], rval); + 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); } @@ -664,7 +685,7 @@ bool js_cocos2dx_MenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) ; JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_MenuItem_setCallback : Error processing arguments"); cobj->setCallback(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -675,34 +696,34 @@ bool js_cocos2dx_MenuItem_setCallback(JSContext *cx, uint32_t argc, jsval *vp) 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); @@ -722,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"); @@ -731,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"); @@ -739,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; } @@ -749,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); @@ -765,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; } @@ -773,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(); @@ -781,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; @@ -799,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); @@ -818,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) { @@ -833,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) { @@ -844,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; } @@ -862,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) { @@ -882,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]) @@ -900,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) @@ -934,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. @@ -961,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(); @@ -988,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 @@ -1013,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) @@ -1022,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); } @@ -1049,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; } @@ -1061,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(); @@ -1087,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) { @@ -1112,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; } @@ -1220,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); @@ -1268,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) @@ -1351,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() @@ -1403,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) @@ -1439,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) @@ -1462,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) @@ -1494,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); @@ -1505,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); @@ -1520,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"); } @@ -1530,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; @@ -1543,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); } @@ -1571,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"); @@ -1584,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(); @@ -1595,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 ); } // @@ -1603,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 ); } // @@ -1611,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"); @@ -1622,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; @@ -1635,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); } @@ -1652,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"); @@ -1663,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; @@ -1683,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; } @@ -1718,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; } @@ -1728,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) @@ -1737,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. @@ -1751,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); @@ -1767,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"); @@ -1783,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; } @@ -1817,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; } @@ -1827,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); @@ -1835,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. @@ -1855,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); @@ -1866,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); @@ -1874,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; @@ -1887,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"); @@ -1922,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) { @@ -1935,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"); @@ -1944,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); @@ -1952,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. @@ -1966,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); @@ -1984,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); @@ -1992,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 ); } // @@ -2006,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 ); } // @@ -2014,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"); @@ -2031,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; @@ -2043,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"); @@ -2064,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); @@ -2072,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. @@ -2084,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; @@ -2092,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); @@ -2101,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; } @@ -2118,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); @@ -2126,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; } @@ -2141,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) { @@ -2158,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); @@ -2167,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) { @@ -2184,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); @@ -2193,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); @@ -2201,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) { @@ -2212,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; } @@ -2320,7 +2370,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); @@ -2329,21 +2379,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); @@ -2352,7 +2402,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); @@ -2361,21 +2411,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); @@ -2384,7 +2434,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); @@ -2393,21 +2443,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); @@ -2416,7 +2466,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); @@ -2424,16 +2474,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; } @@ -2444,15 +2494,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) { @@ -2476,15 +2526,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) { @@ -2537,7 +2587,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; @@ -2548,11 +2598,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"); @@ -2561,7 +2611,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"); @@ -2576,7 +2627,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; } @@ -2589,16 +2641,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; @@ -2608,13 +2660,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; } @@ -2624,7 +2676,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"); @@ -2632,13 +2685,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; } @@ -2648,16 +2701,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) { @@ -2667,13 +2720,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; } @@ -2721,13 +2774,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); @@ -2736,9 +2789,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); @@ -2861,29 +2915,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]; @@ -2909,7 +2963,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; } @@ -2920,7 +2974,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); @@ -2929,11 +2983,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]; @@ -2944,7 +2998,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; } @@ -2954,19 +3008,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"); @@ -2995,7 +3049,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; } @@ -3005,16 +3059,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"); @@ -3043,7 +3097,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; } @@ -3053,7 +3107,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); @@ -3061,11 +3115,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++) { @@ -3078,7 +3132,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; } @@ -3115,7 +3169,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); @@ -3125,24 +3179,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; } @@ -3169,15 +3223,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; } @@ -3190,19 +3244,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; } @@ -3213,19 +3267,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; } @@ -3236,19 +3290,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; } @@ -3258,21 +3312,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; } @@ -3282,16 +3336,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; } @@ -3302,17 +3356,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; } @@ -3323,17 +3377,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; } @@ -3344,19 +3398,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; } @@ -3367,21 +3421,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; } @@ -3392,19 +3446,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; } @@ -3416,19 +3470,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; } @@ -3439,19 +3493,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; } @@ -3462,17 +3516,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; } @@ -3484,17 +3538,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; } @@ -3506,19 +3560,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; } @@ -3529,19 +3583,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; } @@ -3552,17 +3606,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; } @@ -3571,42 +3625,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"); @@ -3614,7 +3846,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; } @@ -3624,20 +3856,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"); @@ -3646,20 +3877,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"); @@ -3668,7 +3899,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"); @@ -3676,7 +3908,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; } @@ -3688,7 +3920,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; @@ -3700,11 +3932,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); @@ -3717,13 +3949,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); @@ -3731,17 +3964,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"); @@ -3766,7 +3999,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; } @@ -3787,9 +4020,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; } } @@ -3815,7 +4048,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); @@ -3836,7 +4069,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); @@ -3845,10 +4078,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); @@ -3856,7 +4089,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"); @@ -3865,7 +4099,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); @@ -3874,7 +4108,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); @@ -3883,7 +4117,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); @@ -3898,8 +4132,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); @@ -3913,6 +4147,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); @@ -3922,7 +4157,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); @@ -3931,7 +4166,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); @@ -3939,12 +4174,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; } @@ -3954,7 +4189,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); @@ -3965,33 +4200,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; @@ -3999,7 +4234,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); @@ -4007,8 +4242,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(); @@ -4030,7 +4265,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; } @@ -4038,7 +4273,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); @@ -4046,8 +4281,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); @@ -4067,20 +4302,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; } @@ -4088,6 +4324,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); \ @@ -4126,6 +4436,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); @@ -4133,16 +4444,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; } @@ -4152,7 +4463,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); @@ -4161,16 +4472,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; } @@ -4179,7 +4490,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(); @@ -4196,7 +4509,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; } @@ -4205,22 +4518,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; @@ -4358,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; @@ -4377,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); @@ -4391,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); @@ -4406,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; } @@ -4416,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); @@ -4426,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; } @@ -4441,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; @@ -4453,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); @@ -4469,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); @@ -4487,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 { @@ -4510,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); } @@ -4523,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); @@ -4531,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); @@ -4544,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); @@ -4559,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 { @@ -4579,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); } @@ -4592,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); @@ -4601,6 +4919,100 @@ 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; + } + + 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; +} // EventKeyboard class bindings, need manual bind for transform key codes @@ -4609,17 +5021,17 @@ JSObject *jsb_cocos2d_EventKeyboard_prototype; bool js_cocos2dx_EventKeyboard_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::EventKeyboard::KeyCode arg0; ScriptingCore *core = ScriptingCore::getInstance(); - jsval retVal; - core->executeFunctionWithOwner(OBJECT_TO_JSVAL(core->getGlobalObject()), "parseKeyCode", argc, argv, &retVal); + 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, argv[1])); + arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); @@ -4635,11 +5047,11 @@ bool js_cocos2dx_EventKeyboard_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, 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"); + JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventKeyboard"); return true; } @@ -4650,13 +5062,14 @@ 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, 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().set(BOOLEAN_TO_JSVAL(true)); return true; } -void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global) { +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; @@ -4670,8 +5083,8 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global) { 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} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_ENUMERATE | JSPROP_PERMANENT), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -4682,7 +5095,7 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global) { jsb_cocos2d_EventKeyboard_prototype = JS_InitClass( cx, global, - jsb_cocos2d_Event_prototype, + JS::RootedObject(cx, jsb_cocos2d_Event_prototype), jsb_cocos2d_EventKeyboard_class, js_cocos2dx_EventKeyboard_constructor, 0, // constructor properties, @@ -4711,14 +5124,14 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JSObject *global) { // 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; } @@ -4726,209 +5139,243 @@ 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); + + JS::RootedObject labelProto(cx, jsb_cocos2d_Label_prototype); + JS_DefineFunction(cx, labelProto, "setTTFConfig", js_cocos2dx_Label_setTTFConfig, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject nodeGridProto(cx, jsb_cocos2d_NodeGrid_prototype); + JS_DefineFunction(cx, nodeGridProto, "setGrid", js_cocos2dx_NodeGrid_setGrid, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject nodeProto(cx, jsb_cocos2d_Node_prototype); + JS_DefineFunction(cx, nodeProto, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "onEnter", js_cocos2dx_Node_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "onExit", js_cocos2dx_Node_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "init", js_doNothing, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "schedule", js_CCNode_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "scheduleUpdateWithPriority", js_cocos2dx_CCNode_scheduleUpdateWithPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "unscheduleUpdate", js_cocos2dx_CCNode_unscheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "scheduleUpdate", js_cocos2dx_CCNode_scheduleUpdate, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "unschedule", js_CCNode_unschedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "unscheduleAllCallbacks", js_cocos2dx_CCNode_unscheduleAllSelectors, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "setPosition", js_cocos2dx_CCNode_setPosition, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "setContentSize", js_cocos2dx_CCNode_setContentSize, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "setAnchorPoint", js_cocos2dx_CCNode_setAnchorPoint, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "setColor", js_cocos2dx_CCNode_setColor, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "pause", js_cocos2dx_CCNode_pause, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "resume", js_cocos2dx_CCNode_resume, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, nodeProto, "setAdditionalTransform", js_cocos2dx_Node_setAdditionalTransform, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject eventListenerProto(cx, jsb_cocos2d_EventListener_prototype); + JS_DefineFunction(cx, eventListenerProto, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, eventListenerProto, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject touchProto(cx, jsb_cocos2d_Touch_prototype); + JS_DefineFunction(cx, touchProto, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, touchProto, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject eventTouchProto(cx, jsb_cocos2d_EventTouch_prototype); + JS_DefineFunction(cx, eventTouchProto, "getTouches", js_cocos2dx_EventTouch_getTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, eventTouchProto, "setTouches", js_cocos2dx_EventTouch_setTouches, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject glProgramProto(cx, jsb_cocos2d_GLProgram_prototype); + JS_DefineFunction(cx, glProgramProto, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, glProgramProto, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, glProgramProto, "setUniformLocationF32", js_cocos2dx_CCGLProgram_setUniformLocationWith4f, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, glProgramProto, "getProgram", js_cocos2dx_CCGLProgram_getProgram, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject glProgramStateProto(cx, jsb_cocos2d_GLProgramState_prototype); + JS_DefineFunction(cx, glProgramStateProto, "setVertexAttribPointer", js_cocos2dx_GLProgramState_setVertexAttribPointer, 6, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, glProgramStateProto, "setUniformVec4", js_cocos2dx_GLProgramState_setUniformVec4, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject componentProto(cx, jsb_cocos2d_Component_prototype); + JS_DefineFunction(cx, componentProto, "onEnter", js_cocos2dx_Component_onEnter, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, componentProto, "onExit", js_cocos2dx_Component_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject schedulerProto(cx, jsb_cocos2d_Scheduler_prototype); + JS_DefineFunction(cx, schedulerProto, "resumeTarget", js_cocos2dx_CCScheduler_resumeTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "pauseTarget", js_cocos2dx_CCScheduler_pauseTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "scheduleUpdateForTarget", js_CCScheduler_scheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "unscheduleUpdateForTarget", js_CCScheduler_unscheduleUpdateForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "scheduleCallbackForTarget", js_CCScheduler_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "unscheduleCallbackForTarget", js_CCScheduler_unscheduleCallbackForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "unscheduleAllCallbacksForTarget", js_cocos2dx_CCScheduler_unscheduleAllSelectorsForTarget, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "unscheduleAllCallbacks", js_cocos2dx_CCScheduler_unscheduleAll, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "unscheduleAllCallbacksWithMinPriority", js_cocos2dx_CCScheduler_unscheduleAllCallbacksWithMinPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, schedulerProto, "isTargetPaused", js_cocos2dx_CCScheduler_isTargetPaused, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_TMXLayer_prototype), "getTileFlagsAt", js_cocos2dx_CCTMXLayer_getTileFlagsAt, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_DrawNode_prototype), "drawPoly", js_cocos2dx_CCDrawNode_drawPolygon, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Texture2D_prototype), "setTexParameters", js_cocos2dx_CCTexture2D_setTexParameters, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject menuProto(cx, jsb_cocos2d_Menu_prototype); + JS_DefineFunction(cx, menuProto, "alignItemsInRows", js_cocos2dx_CCMenu_alignItemsInRows, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, menuProto, "alignItemsInColumns", js_cocos2dx_CCMenu_alignItemsInColumns, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Layer_prototype), "init", js_cocos2dx_CCLayer_init, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject fileUtilsProto(cx, jsb_cocos2d_FileUtils_prototype); + JS_DefineFunction(cx, fileUtilsProto, "setSearchResolutionsOrder", js_cocos2dx_CCFileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT ); + JS_DefineFunction(cx, fileUtilsProto, "setSearchPaths", js_cocos2dx_CCFileUtils_setSearchPaths, 1, JSPROP_PERMANENT ); + JS_DefineFunction(cx, fileUtilsProto, "getSearchPaths", js_cocos2dx_CCFileUtils_getSearchPaths, 0, JSPROP_PERMANENT ); + JS_DefineFunction(cx, fileUtilsProto, "getSearchResolutionsOrder", js_cocos2dx_CCFileUtils_getSearchResolutionsOrder, 0, JSPROP_PERMANENT ); + JS_DefineFunction(cx, fileUtilsProto, "createDictionaryWithContentsOfFile", js_cocos2dx_FileUtils_createDictionaryWithContentsOfFile, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, fileUtilsProto, "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 = anonEvaluate(cx, global, "(function () { return cc.EventListenerFocus; })()").toObjectOrNull(); + JS_GetProperty(cx, ccObj, "EventListenerFocus", &tmpVal); + tmpObj = tmpVal.toObjectOrNull(); JS_DefineFunction(cx, tmpObj, "create", js_EventListenerFocus_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); - - tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierBy; })()")); + + 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; })()")); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_BezierBy_prototype), "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); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_BezierTo_prototype), "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; })()")); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_CardinalSplineTo_prototype), "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); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_CatmullRomBy_prototype), "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_MenuItem_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; })()")); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_CatmullRomTo_prototype), "initWithDuration", JSB_CatmullRomBy_initWithDuration, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Sprite_prototype), "textureLoaded", js_cocos2dx_CCSprite_textureLoaded, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_SpriteBatchNode_prototype), "getDescendants", js_cocos2dx_SpriteBatchNode_getDescendants, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Action_prototype), "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Action_prototype), "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Animation_prototype), "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Animation_prototype), "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_SpriteFrame_prototype), "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_SpriteFrame_prototype), "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_MenuItem_prototype), "setCallback", js_cocos2dx_MenuItem_setCallback, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_TMXLayer_prototype), "getTileFlagsAt", js_cocos2dx_CCTMXLayer_tileFlagsAt, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_TMXLayer_prototype), "getTiles", js_cocos2dx_CCTMXLayer_getTiles, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS::RootedObject actionIntervalProto(cx, jsb_cocos2d_ActionInterval_prototype); + JS_DefineFunction(cx, actionIntervalProto, "repeat", js_cocos2dx_ActionInterval_repeat, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, actionIntervalProto, "repeatForever", js_cocos2dx_ActionInterval_repeatForever, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, actionIntervalProto, "_speed", js_cocos2dx_ActionInterval_speed, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, actionIntervalProto, "easing", js_cocos2dx_ActionInterval_easing, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_RenderTexture_prototype), "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; })()")); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Scene_prototype), "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); + JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_CallFuncN_prototype), "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); + JS::RootedObject camera(cx, jsb_cocos2d_Camera_prototype); + JS_DefineFunction(cx, camera, "unproject", js_cocos2dx_Camera_unproject, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, camera, "isVisibleInFrustum", js_cocos2dx_Camera_isVisibleInFrustum, 1, 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); @@ -4948,11 +5395,27 @@ 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_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); + + JS::RootedObject mathObj(cx); + get_or_create_js_obj(cx, ccObj, "math", &mathObj); + JS_DefineFunction(cx, mathObj, "obbGetCorners", js_cocos2dx_ccobbGetCorners, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "obbIntersectsObb", js_cocos2dx_ccobbIntersects, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "rayIntersectsObb", js_cocos2dx_ccrayIntersectsObb, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "mat4CreateTranslation", js_cocos2dx_ccmat4CreateTranslation, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "mat4CreateRotation", js_cocos2dx_ccmat4CreateRotation, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "mat4Multiply", js_cocos2dx_ccmat4Multiply, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "mat4MultiplyVec3", js_cocos2dx_ccmat4MultiplyVec3, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, mathObj, "quatMultiply", js_cocos2dx_ccquatMultiply, 2, JSPROP_READONLY | JSPROP_PERMANENT); + js_register_cocos2dx_EventKeyboard(cx, ccObj); - + JS::RootedObject consoleObj(cx); - create_js_root_obj(cx, global, "console", &consoleObj); + get_or_create_js_obj(cx, global, "console", &consoleObj); JS_DefineFunction(cx, consoleObj, "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 index 3d0fc6bf3f..f996404c8c 100644 --- a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp @@ -27,18 +27,18 @@ jsval animationInfo_to_jsval(JSContext* cx, const cocostudio::timeline::AnimationInfo& v) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", std_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "startIndex", uint32_to_jsval(cx, v.startIndex), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "endIndex", uint32_to_jsval(cx, v.endIndex), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + 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, jsval vp, cocostudio::timeline::AnimationInfo* ret) +bool jsval_to_animationInfo(JSContext* cx, JS::HandleValue vp, cocostudio::timeline::AnimationInfo* ret) { JS::RootedObject tmp(cx); JS::RootedValue jsName(cx); @@ -48,7 +48,7 @@ bool jsval_to_animationInfo(JSContext* cx, jsval vp, cocostudio::timeline::Anima double startIndex, endIndex; bool ok = vp.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, vp), &tmp) && + JS_ValueToObject(cx, vp, &tmp) && JS_GetProperty(cx, tmp, "name", &jsName) && JS_GetProperty(cx, tmp, "startIndex", &jsStartId) && JS_GetProperty(cx, tmp, "endIndex", &jsEndId) && 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 index 1c0686a204..513d2847f9 100644 --- a/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.h +++ b/frameworks/js-bindings/bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.h @@ -24,8 +24,7 @@ #ifndef __cocos2d_js_bindings__jsb_cocos2dx_studio_conversions__ #define __cocos2d_js_bindings__jsb_cocos2dx_studio_conversions__ -#include "js/Value.h" -#include "js/TypeDecls.h" +#include "jsapi.h" namespace cocostudio { @@ -36,6 +35,6 @@ namespace cocostudio } extern jsval animationInfo_to_jsval(JSContext* cx, const cocostudio::timeline::AnimationInfo& v); -extern bool jsval_to_animationInfo(JSContext* cx, jsval vp, cocostudio::timeline::AnimationInfo* ret); +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 708f69a77e..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)); @@ -288,7 +288,7 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *cx, uint32_t argc, jsval *vp) { - 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,24 +298,24 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c const char* arg0; const char* arg1; cocos2d::Ref* 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 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 (!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_ActionManagerEx_initWithDictionaryEx : Error processing arguments"); cobj->initWithDictionary(arg0, arg1Jsondoc, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -330,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; } @@ -378,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."); @@ -404,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."); @@ -430,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."); @@ -456,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."); @@ -482,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."); @@ -508,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."); @@ -534,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."); @@ -560,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."); @@ -586,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."); @@ -612,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."); @@ -638,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."); @@ -664,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."); @@ -690,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."); @@ -719,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; @@ -748,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; @@ -762,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) { @@ -801,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); @@ -836,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."); @@ -874,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; @@ -902,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."); @@ -928,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."); @@ -954,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."); @@ -980,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."); @@ -1006,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."); @@ -1032,7 +1033,7 @@ 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."); @@ -1048,7 +1049,7 @@ bool js_get_ContourData_vertexList(JSContext *cx, JS::HandleObject obj, JS::Hand 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, nullptr)); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); jsval jsret; //CCObject* obj; int i = 0; @@ -1057,7 +1058,7 @@ bool js_get_ContourData_vertexList(JSContext *cx, JS::HandleObject obj, JS::Hand JS::RootedValue arrElement(cx); arrElement = vector2_to_jsval(cx, vec2); - if (!JS_SetElement(cx, jsretArr, i, &arrElement)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -1081,7 +1082,7 @@ bool js_set_ContourData_vertexList(JSContext *cx, JS::HandleObject obj, JS::Hand cocostudio::ContourData* cobj = (cocostudio::ContourData*)(proxy ? proxy->ptr : NULL); if (cobj) { JS::RootedObject jsListObj(cx); - jsListObj = JSVAL_TO_OBJECT(vp.get()); + jsListObj = vp.get().toObjectOrNull(); JSB_PRECONDITION3(jsListObj && JS_IsArrayObject(cx, jsListObj), cx, false, "Object must be an array"); std::vector list; @@ -1119,7 +1120,7 @@ bool js_get_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS: 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, nullptr)); + JS::RootedObject jsretArr(cx, JS_NewArrayObject(cx, 0)); jsval jsret; //CCObject* obj; int i = 0; @@ -1129,7 +1130,7 @@ bool js_get_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS: 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)) { + if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } ++i; @@ -1153,7 +1154,7 @@ bool js_set_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS: cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { JS::RootedObject jsListObj(cx); - jsListObj = JSVAL_TO_OBJECT(vp.get()); + jsListObj = vp.get().toObjectOrNull(); JSB_PRECONDITION3(jsListObj && JS_IsArrayObject(cx, jsListObj), cx, false, "Object must be an array"); cocos2d::Vector list; @@ -1170,7 +1171,7 @@ bool js_set_TextureData_contourDataList(JSContext *cx, JS::HandleObject obj, JS: 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); contourData = (cocostudio::ContourData*)(jsProxy ? jsProxy->ptr : NULL); JSB_PRECONDITION2(contourData, cx, false, "Invalid Native Object"); @@ -1219,7 +1220,7 @@ bool js_set_TextureData_width(JSContext *cx, JS::HandleObject obj, JS::HandleId js_proxy_t *proxy = jsb_get_js_proxy(jsobj); cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { - cobj->width = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->width = (float)(vp.get().toNumber()); return true; } JS_ReportError(cx, "js_set_TextureData_width : Invalid native object."); @@ -1251,7 +1252,7 @@ bool js_set_TextureData_height(JSContext *cx, JS::HandleObject obj, JS::HandleId js_proxy_t *proxy = jsb_get_js_proxy(jsobj); cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { - cobj->height = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->height = (float)vp.get().toNumber(); return true; } JS_ReportError(cx, "js_set_TextureData_height : Invalid native object."); @@ -1283,7 +1284,7 @@ bool js_set_TextureData_pivotX(JSContext *cx, JS::HandleObject obj, JS::HandleId js_proxy_t *proxy = jsb_get_js_proxy(jsobj); cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { - cobj->pivotX = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->pivotX = (float)vp.get().toNumber(); return true; } JS_ReportError(cx, "js_set_TextureData_pivotX : Invalid native object."); @@ -1315,7 +1316,7 @@ bool js_set_TextureData_pivotY(JSContext *cx, JS::HandleObject obj, JS::HandleId js_proxy_t *proxy = jsb_get_js_proxy(jsobj); cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { - cobj->pivotY = (float)JSVAL_TO_DOUBLE(vp.get()); + cobj->pivotY = (float)vp.get().toNumber(); return true; } JS_ReportError(cx, "js_set_TextureData_pivotY : Invalid native object."); @@ -1348,7 +1349,7 @@ bool js_set_TextureData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId i cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); 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_TextureData_name : Error processing arguments"); cobj->name = name; return true; @@ -1368,71 +1369,56 @@ 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, 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_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, jsb_cocostudio_ArmatureDataManager_prototype, "addArmatureFileInfoAsync", jsb_Animation_addArmatureFileInfoAsyncCallFunc, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, jsb_cocostudio_ActionManagerEx_prototype, "initWithDictionaryEx", js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE); - - 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); - - 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); - - static JSPropertySpec contourDataProps[] = { - {"vertexList", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_ContourData_vertexList), JSOP_WRAPPER(js_set_ContourData_vertexList)}, - {0, 0, 0, 0, 0} - }; - JS_DefineProperties(cx, jsb_cocostudio_ContourData_prototype, contourDataProps); - - static JSPropertySpec textureDataProps[] = { - {"contourDataList", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_contourDataList), JSOP_WRAPPER(js_set_TextureData_contourDataList)}, - {"name", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_name), JSOP_WRAPPER(js_set_TextureData_name)}, - {"width", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_width), JSOP_WRAPPER(js_set_TextureData_width)}, - {"height", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_height), JSOP_WRAPPER(js_set_TextureData_height)}, - {"pivotX", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_pivotX), JSOP_WRAPPER(js_set_TextureData_pivotX)}, - {"pivotY", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_get_TextureData_pivotY), JSOP_WRAPPER(js_set_TextureData_pivotY)}, - {0, 0, 0, 0, 0} - }; - JS_DefineProperties(cx, jsb_cocostudio_TextureData_prototype, textureDataProps); + 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); + 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..4e318ff3a2 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 @@ -45,7 +45,7 @@ class JSB_ScrollViewDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -55,7 +55,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 +64,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 +77,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 +96,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 +105,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 +131,7 @@ class JSB_TableViewDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -175,7 +175,7 @@ class JSB_TableViewDelegate { _needUnroot = true; JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); + JS::AddNamedObjectRoot(cx, &_JSDelegate, "TableViewDelegate"); } } @@ -187,7 +187,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 +202,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 +220,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 +238,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 +260,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 +287,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 +307,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 +330,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 +346,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 +361,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 +379,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 +395,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 +416,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 +432,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 +442,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 +481,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 +498,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 +508,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 +518,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 +534,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 +551,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 +577,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 +606,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 +621,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 +631,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 +641,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 +652,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 +661,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 +674,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 +702,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 +712,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 +722,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; @@ -916,8 +919,8 @@ __JSDownloaderDelegator::__JSDownloaderDelegator(JSContext *cx, JSObject *obj, c _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"); + if (!_jsCallback.isNull()) { + JS::AddNamedValueRoot(globalCx, &_jsCallback, "JSB_DownloadDelegator_jsCallback"); } long contentSize = _downloader->getContentSize(_url); @@ -942,19 +945,19 @@ __JSDownloaderDelegator::~__JSDownloaderDelegator() void __JSDownloaderDelegator::onError(const cocos2d::extension::Downloader::Error &error) { - if (!JSVAL_IS_NULL(_jsCallback)) { + if (!_jsCallback.isNull()) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JSObject *global = ScriptingCore::getInstance()->getGlobalObject(); + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); JSAutoCompartment ac(_cx, _obj); 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::RootedValue retval(cx); + //JS_AddValueRoot(cx, &succeed); + JS_CallFunctionValue(cx, global, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(1, &succeed), &retval); + //JS_RemoveValueRoot(cx, &succeed); - JS_RemoveValueRoot(cx, &_jsCallback); + JS::RemoveValueRoot(cx, &_jsCallback); } this->release(); } @@ -964,7 +967,7 @@ 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()); JSAutoCompartment ac(_cx, _obj); @@ -975,10 +978,10 @@ void __JSDownloaderDelegator::onSuccess(const std::string &srcUrl, const std::st js_type_class_t *classType = js_get_type_from_native(tex); assert(classType); - JSObject *obj = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); + JSObject *obj = JS_NewObject(cx, classType->jsclass, JS::RootedObject(cx, classType->proto), JS::RootedObject(cx, classType->parentProto)); // 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,13 +992,13 @@ 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); + if (!_jsCallback.isNull()) { + JS::RootedValue retval(cx); + //JS_AddValueRoot(cx, valArr); + JS_CallFunctionValue(cx, global, JS::RootedValue(cx, _jsCallback), JS::HandleValueArray::fromMarkedLocation(2, valArr), &retval); + //JS_RemoveValueRoot(cx, valArr); - JS_RemoveValueRoot(cx, &_jsCallback); + JS::RemoveValueRoot(cx, &_jsCallback); } this->release(); } @@ -1008,18 +1011,18 @@ void __JSDownloaderDelegator::download(JSContext *cx, JSObject *obj, const std:: // jsb.loadRemoteImg(url, function(succeed, result) {}) bool js_load_remote_image(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); 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); + jsval callback = 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 +1036,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, "cc", &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..a3fff68815 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 @@ -40,15 +40,15 @@ class __JSDownloaderDelegator : cocos2d::Ref 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; + JS::Heap _jsCallback; unsigned char *_buffer; long _size; std::shared_ptr _downloader; std::string _url; JSContext *_cx; - JSObject *_obj; + JS::Heap _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 2fbcf8c054..5d504836ee 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,25 +518,27 @@ 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)); +bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret) { + JSString *tmp = JS::ToString(cx, v); JSB_PRECONDITION3(tmp, cx, false, "Error processing arguments"); JSStringWrapper str(tmp); @@ -534,13 +546,13 @@ bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) { return true; } -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 +565,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 +574,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 +593,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 +694,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 +725,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 +754,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 +784,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 +793,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 +812,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 +830,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 +839,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 +858,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 +866,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 +884,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 +907,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 +925,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 +952,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 +968,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 +994,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 +1007,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 +1021,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 +1047,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 +1072,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 +1133,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 +1148,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 +1162,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 +1223,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 +1236,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 +1249,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 +1266,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 +1289,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 +1303,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 +1318,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 +1327,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 +1342,9 @@ bool jsval_to_std_vector_string( JSContext *cx, jsval vp, std::vectorpush_back(valueWapper.get()); } else @@ -1253,10 +1358,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 +1373,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 +1393,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 +1413,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 +1433,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 +1453,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,7 +1461,7 @@ 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) && @@ -1373,14 +1478,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) && @@ -1398,7 +1532,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; @@ -1438,7 +1572,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; @@ -1448,7 +1582,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) { @@ -1495,40 +1632,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(); } @@ -1538,7 +1675,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. @@ -1564,12 +1701,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) { @@ -1577,7 +1714,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); @@ -1591,7 +1728,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); @@ -1601,7 +1738,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) && @@ -1662,6 +1799,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); @@ -1672,15 +1812,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); } @@ -1690,13 +1839,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); } @@ -1705,12 +1856,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); } @@ -1719,10 +1872,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); } @@ -1731,37 +1886,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); } @@ -1770,57 +1933,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); @@ -1828,11 +2023,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"); @@ -2037,12 +2232,12 @@ bool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition *out ) return true; } -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"); @@ -2084,7 +2279,6 @@ bool jsval_to_CCPoint( JSContext *cx, jsval vp, Point *ret ) #endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES } - jsval ccvalue_to_jsval(JSContext* cx, const cocos2d::Value& v) { jsval ret = JSVAL_NULL; @@ -2123,7 +2317,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) { @@ -2170,7 +2364,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) { @@ -2219,7 +2413,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) @@ -2254,7 +2448,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; @@ -2270,7 +2464,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) @@ -2278,7 +2472,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; @@ -2288,7 +2482,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) @@ -2296,7 +2490,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; @@ -2306,31 +2500,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); } @@ -2339,11 +2530,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); } @@ -2352,10 +2545,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 0c2e142f37..575dc940c6 100644 --- a/frameworks/js-bindings/bindings/manual/js_manual_conversions.h +++ b/frameworks/js-bindings/bindings/manual/js_manual_conversions.h @@ -61,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"); @@ -136,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"); @@ -160,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) @@ -173,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); @@ -259,6 +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); +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); @@ -266,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) @@ -279,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; @@ -290,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 03fd627f79..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; } 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,8 +59,16 @@ 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,8 @@ void MinXmlHttpRequest::_setHttpRequestHeader() } + + /** * @brief Callback for HTTPRequest. Handles the response and invokes Callback. * @param sender Object which initialized callback @@ -170,7 +181,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 +201,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 +234,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 +262,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 +283,8 @@ MinXmlHttpRequest::MinXmlHttpRequest() , _requestHeader() , _isAborted(false) { + _scheduler = cocos2d::Director::getInstance()->getScheduler(); + _scheduler->retain(); } /** @@ -284,10 +293,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 +314,7 @@ MinXmlHttpRequest::~MinXmlHttpRequest() } CC_SAFE_FREE(_data); + CC_SAFE_RELEASE_NULL(_scheduler); } /** @@ -310,65 +329,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 +397,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 +408,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 +443,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 +454,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 +465,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 +504,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 +515,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 +530,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, statusText) if (strVal != JSVAL_NULL) { - vp.set(strVal); + args.rval().set(strVal); return true; } else @@ -529,7 +546,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 +556,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 +577,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText) if (strVal != JSVAL_NULL) { - vp.set(strVal); + args.rval().set(strVal); return true; } } @@ -568,7 +585,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 +598,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,13 +613,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) JS::RootedValue outVal(cx); jsval strVal = std_string_to_jsval(cx, _data); - 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); + + //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; } } @@ -613,11 +632,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); } } @@ -631,15 +650,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); @@ -657,6 +676,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 : ( @@ -669,6 +689,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; @@ -688,7 +710,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! @@ -698,11 +719,12 @@ 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()) { return false; } - JSStringWrapper strWrap(str); + JSStringWrapper strWrap(args.get(0).toString()); data = strWrap.get(); } @@ -716,10 +738,29 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) _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 * @@ -734,6 +775,9 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, abort) //3.Change the state to UNSENT. _readyState = UNSENT; + + _notify(_onabortCallback); + return true; } @@ -743,6 +787,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, abort) */ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getAllResponseHeaders) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); stringstream responseheaders; string responseheader; @@ -756,7 +801,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 @@ -776,9 +821,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); @@ -789,16 +836,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; } } @@ -812,12 +860,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); @@ -850,7 +898,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); + } + + } } /** @@ -858,27 +928,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[] = { @@ -892,8 +969,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..cf263750b2 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,13 @@ 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 _sendRequest(JSContext *cx); + void _notify(JSObject * callback); std::string _url; JSContext* _cx; @@ -94,12 +101,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 +122,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 503b75b5e6..cedeccbf5f 100644 --- a/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm +++ b/frameworks/js-bindings/bindings/manual/platform/ios/JavaScriptObjCBridge.mm @@ -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 b3d3272b56..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,25 +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); } } }; + 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::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 5d42ff87d3..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,12 +24,10 @@ #ifndef __jsb_cocos2dx_spine_manual__ #define __jsb_cocos2dx_spine_manual__ - -#include "js/Value.h" -#include "js/TypeDecls.h" +#include "jsapi.h" #include "spine/spine-cocos2dx.h" -void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global); +void register_all_cocos2dx_spine_manual(JSContext* cx, JS::HandleObject global); extern jsval speventdata_to_jsval(JSContext* cx, spEventData& v); extern jsval spevent_to_jsval(JSContext* cx, spEvent& v); 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 7179c3142e..334223ec20 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,7 +179,7 @@ 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(); @@ -192,8 +192,8 @@ static bool js_cocos2dx_UICheckBox_addEventListener(JSContext *cx, uint32_t argc } 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 +210,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,7 +231,7 @@ 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(); @@ -244,8 +244,8 @@ static bool js_cocos2dx_UISlider_addEventListener(JSContext *cx, uint32_t argc, } 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 +262,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,7 +283,7 @@ 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(); @@ -296,8 +296,8 @@ static bool js_cocos2dx_UITextField_addEventListener(JSContext *cx, uint32_t arg } 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 +314,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,7 +335,7 @@ 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(); @@ -348,8 +348,8 @@ static bool js_cocos2dx_UIPageView_addEventListener(JSContext *cx, uint32_t argc } 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 +366,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,7 +387,7 @@ 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(); @@ -400,8 +400,8 @@ static bool js_cocos2dx_UIScrollView_addEventListener(JSContext *cx, uint32_t ar } 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 +417,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,7 +438,7 @@ 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(); @@ -451,8 +451,8 @@ static bool js_cocos2dx_UIListView_addEventListener(JSContext *cx, uint32_t argc } 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 +469,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); } @@ -515,7 +515,7 @@ static bool js_cocos2dx_LayoutParameter_setMargin(JSContext *cx, uint32_t argc, return true; } else if (argc == 4) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs argv = CallArgsFromVp(argc, vp); bool ok = true; double left, top,right,bottom; ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &left); @@ -540,16 +540,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 { @@ -567,7 +569,7 @@ class JSB_EditBoxDelegate { public: JSB_EditBoxDelegate() - : _JSDelegate(NULL) + : _JSDelegate(nullptr) , _needUnroot(false) {} @@ -576,7 +578,7 @@ class JSB_EditBoxDelegate if (_needUnroot) { JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - JS_RemoveObjectRoot(cx, &_JSDelegate); + JS::RemoveObjectRoot(cx, &_JSDelegate); } } @@ -586,7 +588,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 @@ -595,7 +597,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 @@ -608,7 +610,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 @@ -617,7 +619,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) @@ -630,17 +632,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); @@ -649,7 +651,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); @@ -658,7 +660,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); @@ -675,25 +677,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 bbbaeae845..bb0cef4985 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,6 +138,14 @@ 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 */; }; @@ -240,6 +248,10 @@ 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 = ""; }; @@ -305,6 +317,8 @@ 1A119E2E18BDF19200352BAA /* auto */ = { isa = PBXGroup; children = ( + 420BBCEE1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.cpp */, + 420BBCEF1AA48EDE00493976 /* jsb_cocos2dx_3d_auto.hpp */, 1A119E2F18BDF19200352BAA /* jsb_cocos2dx_auto.cpp */, 1A119E3018BDF19200352BAA /* jsb_cocos2dx_auto.hpp */, 1A119E3218BDF19200352BAA /* jsb_cocos2dx_builder_auto.cpp */, @@ -327,6 +341,7 @@ 1A119E4118BDF19200352BAA /* manual */ = { isa = PBXGroup; children = ( + 420BBCF41AA48EE900493976 /* 3d */, 0541A74C1973876100E45470 /* ios */, 1A119E4218BDF19200352BAA /* chipmunk */, 1A119E4E18BDF19200352BAA /* cocos2d_specifics.cpp */, @@ -493,6 +508,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 = ( @@ -548,11 +572,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 */, @@ -598,8 +624,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 */, @@ -702,12 +730,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 */, @@ -721,6 +751,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 */, @@ -728,6 +759,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 */, diff --git a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj index 5a19d58f6b..6a98e3022e 100644 --- a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj +++ b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj @@ -11,12 +11,14 @@ + + @@ -43,12 +45,14 @@ + + diff --git a/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters b/frameworks/js-bindings/bindings/proj.win32/libJSBinding.vcxproj.filters index de0a62a438..96d80dc2b9 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} + @@ -125,6 +128,12 @@ manual\cocostudio + + auto + + + manual\3d + @@ -238,5 +247,11 @@ manual\cocostudio + + auto + + + manual\3d + \ No newline at end of file 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..cb5b3edf07 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj @@ -0,0 +1,247 @@ + + + + + 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;%(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) + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + _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;%(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 + + + Console + false + + + /IGNORE:4264 %(AdditionalOptions) + + + + + 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..9b1886acd1 --- /dev/null +++ b/frameworks/js-bindings/bindings/proj.wp8/libJSBinding.vcxproj.filters @@ -0,0 +1,255 @@ + + + + + {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 + + + 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 + + + \ 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..c22465518a --- /dev/null +++ b/frameworks/js-bindings/bindings/script/3d/jsb_cocos2d_3d.js @@ -0,0 +1,246 @@ +/**************************************************************************** + 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 +}; + +cc.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); +}; + +cc.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); + } +}; + +cc.BillBoard.prototype._ctor = function(filename, rect, mode = cc.BillBoard.Mode.VIEW_POINT_ORIENTED){ + if(filename !== undefined && filename instanceof cc.Texture2D){ + rect = rect || cc.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(cc.BillBoard.Mode.VIEW_POINT_ORIENTED); + } + }else{ + filename = filename || cc.BillBoard.Mode.VIEW_POINT_ORIENTED; + this.init(); + this.setMode(filename); + } +} \ No newline at end of file diff --git a/frameworks/js-bindings/bindings/script/jsb.js b/frameworks/js-bindings/bindings/script/jsb.js index 97db22e7ac..dd0a188c56 100644 --- a/frameworks/js-bindings/bindings/script/jsb.js +++ b/frameworks/js-bindings/bindings/script/jsb.js @@ -129,3 +129,7 @@ if (jsb.fileUtils.isFileExist('jsb_pluginx.js')) { if (window.sp) { require('script/jsb_spine.js'); } + +if(cc.Sprite3D){ + require('script/3d/jsb_cocos2d_3d.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 9e85eeb6ad..bedc63811a 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"); + }); } }, /** @@ -932,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; @@ -944,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 @@ -1195,6 +1211,7 @@ cc._initSys = function(config, CONFIG_KEY){ * @type {string} */ locSys.OS_ANDROID = "Android"; + locSys.OS_WP8 = "WP8"; locSys.OS_UNKNOWN = "unknown"; /** @@ -1346,7 +1363,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) ? true : false; locSys.language = (function(){ var language = cc.Application.getInstance().getCurrentLanguage(); diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index e20bce2009..1e319e4cb0 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.3"; +cc.ENGINE_VERSION = "Cocos2d-JS v3.4 Beta0"; cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL = 0; cc.DIRECTOR_STATS_POSITION = {x: 0, y: 0}; @@ -2172,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]; 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_create_apis.js b/frameworks/js-bindings/bindings/script/jsb_create_apis.js index 7b0dab4c3c..19e75082ba 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."); + } }; @@ -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; @@ -802,7 +812,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); + } }; 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/studio/jsb_cocos2d_studio.js b/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js index 7fec49dc03..71f1a443d5 100644 --- a/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js +++ b/frameworks/js-bindings/bindings/script/studio/jsb_cocos2d_studio.js @@ -63,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/parsers/timelineParser-2.x.js b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js index 786ed9e867..107306e900 100644 --- a/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js +++ b/frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js @@ -209,7 +209,7 @@ // WIDGET // //////////// - parser.widgetAttributes = function(widget, json){ + parser.widgetAttributes = function(widget, json) { widget.setCascadeColorEnabled(true); widget.setCascadeOpacityEnabled(true); @@ -219,7 +219,7 @@ setContentSize(widget, json["Size"]); var name = json["Name"]; - if(name) + if (name) widget.setName(name); var actionTag = json["ActionTag"] || 0; @@ -227,25 +227,25 @@ widget.setUserObject(new ccs.ActionTimelineData(actionTag)); var rotationSkewX = json["RotationSkewX"]; - if(rotationSkewX) + if (rotationSkewX) widget.setRotationX(rotationSkewX); var rotationSkewY = json["RotationSkewY"]; - if(rotationSkewY) + if (rotationSkewY) widget.setRotationY(rotationSkewY); //var rotation = json["Rotation"]; var flipX = json["FlipX"]; - if(flipX) + if (flipX) widget.setFlippedX(true); var flipY = json["FlipY"]; - if(flipY) + if (flipY) widget.setFlippedY(true); var zOrder = json["zOrder"]; - if(zOrder != null) + if (zOrder != null) widget.setLocalZOrder(zOrder); //var visible = json["Visible"]; @@ -254,7 +254,7 @@ widget.setVisible(visible); var alpha = json["Alpha"]; - if(alpha != null) + if (alpha != null) widget.setOpacity(alpha); widget.setTag(json["Tag"] || 0); @@ -265,19 +265,19 @@ // -- var frameEvent = json["FrameEvent"]; var callBackType = json["CallBackType"]; - if(callBackType != null) + if (callBackType != null) widget.setCallbackType(callBackType); var callBackName = json["CallBackName"]; - if(callBackName) + if (callBackName) widget.setCallbackName(callBackName); var position = json["Position"]; - if(position != null) + if (position != null) widget.setPosition(position["X"] || 0, position["Y"] || 0); var scale = json["Scale"]; - if(scale != null){ + if (scale != null) { var scaleX = getParam(scale["ScaleX"], 1); var scaleY = getParam(scale["ScaleY"], 1); widget.setScaleX(scaleX); @@ -285,80 +285,77 @@ } var anchorPoint = json["AnchorPoint"]; - if(anchorPoint != null) + if (anchorPoint != null) widget.setAnchorPoint(anchorPoint["ScaleX"] || 0, anchorPoint["ScaleY"] || 0); var color = json["CColor"]; - if(color != null) + if (color != null) widget.setColor(getColor(color)); - if(widget instanceof ccui.Layout){ - var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget); - - 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); + var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget); - layoutComponent.setTopMargin(topMargin); - layoutComponent.setBottomMargin(bottomMargin); - layoutComponent.setLeftMargin(leftMargin); - layoutComponent.setRightMargin(rightMargin); + 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); }; /** diff --git a/frameworks/js-bindings/cocos2d-x b/frameworks/js-bindings/cocos2d-x index 02ff0ded28..83b0eeacff 160000 --- a/frameworks/js-bindings/cocos2d-x +++ b/frameworks/js-bindings/cocos2d-x @@ -1 +1 @@ -Subproject commit 02ff0ded281837079063503e1bfa8cf9ce4b20e6 +Subproject commit 83b0eeacff877f630f61166b351308463d6b71c3 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..4ef03a803f --- /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 34 +#define MOZJS_MINOR_VERSION 0 + +#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..7041361b04 --- /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 34 +#define MOZJS_MINOR_VERSION 0 + +#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..3a1cbc16f7 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 @@ -9,15 +9,13 @@ * * The format for each JS error message is: * - * MSG_DEF(, , , , + * 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. * @@ -31,7 +29,7 @@ * * e.g. * - * MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2, + * MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 2, JSEXN_NONE, * "{0} is not a member of the {1} family") * * can be used: @@ -41,395 +39,397 @@ * 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, 1, JSEXN_SYNTAXERR, "unterminated character class {0}") -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_UNUSED173, 173, 0, JSEXN_NONE, "") -MSG_DEF(JSMSG_UNUSED174, 174, 0, JSEXN_NONE, "") -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_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_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_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_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_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_UNUSED210, 210, 0, JSEXN_NONE, "") -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_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_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_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_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_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_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_ERR, "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_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_HANDLE_BAD_ARGS, 364, 2, JSEXN_TYPEERR, "argument {0} invalid: expected {1}") -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_NOT_AN_ERROR, 0, JSEXN_NONE, "") +MSG_DEF(JSMSG_NOT_DEFINED, 1, JSEXN_REFERENCEERR, "{0} is not defined") +MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, JSEXN_TYPEERR, "{0} requires more than {1} argument{2}") +MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 3, JSEXN_TYPEERR, "{0}.prototype.{1} called on incompatible {2}") +MSG_DEF(JSMSG_NO_CONSTRUCTOR, 1, JSEXN_TYPEERR, "{0} has no constructor") +MSG_DEF(JSMSG_BAD_SORT_ARG, 0, JSEXN_TYPEERR, "invalid Array.prototype.sort argument") +MSG_DEF(JSMSG_CANT_WATCH, 1, JSEXN_TYPEERR, "can't watch non-native objects of class {0}") +MSG_DEF(JSMSG_READ_ONLY, 1, JSEXN_TYPEERR, "{0} is read-only") +MSG_DEF(JSMSG_CANT_DELETE, 1, JSEXN_TYPEERR, "property {0} is non-configurable and can't be deleted") +MSG_DEF(JSMSG_NOT_FUNCTION, 1, JSEXN_TYPEERR, "{0} is not a function") +MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 1, JSEXN_TYPEERR, "{0} is not a constructor") +MSG_DEF(JSMSG_CANT_CONVERT, 1, JSEXN_ERR, "can't convert {0} to an integer") +MSG_DEF(JSMSG_CANT_CONVERT_TO, 2, JSEXN_TYPEERR, "can't convert {0} to {1}") +MSG_DEF(JSMSG_NO_PROPERTIES, 1, JSEXN_TYPEERR, "{0} has no properties") +MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}") +MSG_DEF(JSMSG_ARG_INDEX_OUT_OF_RANGE, 1, JSEXN_RANGEERR, "argument {0} accesses an index that is out of range") +MSG_DEF(JSMSG_SPREAD_TOO_LARGE, 0, JSEXN_RANGEERR, "array too large due to spread operand(s)") +MSG_DEF(JSMSG_BAD_WEAKMAP_KEY, 0, JSEXN_TYPEERR, "cannot use the given object as a weak map key") +MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 1, JSEXN_TYPEERR, "invalid {0} usage") +MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 0, JSEXN_RANGEERR, "invalid array length") +MSG_DEF(JSMSG_REDECLARED_VAR, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}") +MSG_DEF(JSMSG_UNDECLARED_VAR, 1, JSEXN_REFERENCEERR, "assignment to undeclared variable {0}") +MSG_DEF(JSMSG_GETTER_ONLY, 0, JSEXN_TYPEERR, "setting a property that has only a getter") +MSG_DEF(JSMSG_UNDEFINED_PROP, 1, JSEXN_REFERENCEERR, "reference to undefined property {0}") +MSG_DEF(JSMSG_INVALID_MAP_ITERABLE, 0, JSEXN_TYPEERR, "iterable for map should have array-like objects") +MSG_DEF(JSMSG_NESTING_GENERATOR, 0, JSEXN_TYPEERR, "already executing generator") +MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}") +MSG_DEF(JSMSG_OBJECT_WATCH_DEPRECATED, 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, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_BAD_SURROGATE_CHAR, 1, JSEXN_TYPEERR, "bad surrogate character {0}") +MSG_DEF(JSMSG_UTF8_CHAR_TOO_LARGE, 1, JSEXN_TYPEERR, "UTF-8 character {0} too large") +MSG_DEF(JSMSG_MALFORMED_UTF8_CHAR, 1, JSEXN_TYPEERR, "malformed UTF-8 character sequence at offset {0}") +MSG_DEF(JSMSG_WRONG_CONSTRUCTOR, 1, JSEXN_TYPEERR, "wrong constructor called for {0}") +MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 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_BAD_GENERATOR_YIELD, 1, JSEXN_TYPEERR, "yield from closing generator {0}") +MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value") +MSG_DEF(JSMSG_UNEXPECTED_TYPE, 2, JSEXN_TYPEERR, "{0} is {1}") +MSG_DEF(JSMSG_MISSING_FUN_ARG, 2, JSEXN_TYPEERR, "missing argument {0} when calling function {1}") +MSG_DEF(JSMSG_NOT_NONNULL_OBJECT, 0, JSEXN_TYPEERR, "value is not a non-null object") +MSG_DEF(JSMSG_INVALID_DESCRIPTOR, 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, 1, JSEXN_TYPEERR, "{0} is not extensible") +MSG_DEF(JSMSG_CANT_REDEFINE_PROP, 1, JSEXN_TYPEERR, "can't redefine non-configurable property '{0}'") +MSG_DEF(JSMSG_CANT_APPEND_TO_ARRAY, 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, 0, JSEXN_TYPEERR, "can't redefine array length") +MSG_DEF(JSMSG_CANT_DEFINE_PAST_ARRAY_LENGTH, 0, JSEXN_TYPEERR, "can't define array index property past the end of an array with non-writable length") +MSG_DEF(JSMSG_BAD_GET_SET_FIELD, 1, JSEXN_TYPEERR, "property descriptor's {0} field is neither undefined nor a function") +MSG_DEF(JSMSG_THROW_TYPE_ERROR, 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_NOT_EXPECTED_TYPE, 3, JSEXN_TYPEERR, "{0}: expected {1}, got {2}") +MSG_DEF(JSMSG_NEED_DEBUG_MODE, 0, JSEXN_ERR, "function can be called only in debug mode") +MSG_DEF(JSMSG_NOT_ITERABLE, 1, JSEXN_TYPEERR, "{0} is not iterable") +MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 2, JSEXN_NONE, "{0} is being assigned a {1}, but already has one") +MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") +MSG_DEF(JSMSG_WRONG_VALUE, 2, JSEXN_ERR, "expected {0} but found {1}") +MSG_DEF(JSMSG_SETPROTOTYPEOF_FAIL, 1, JSEXN_TYPEERR, "[[SetPrototypeOf]] failed on {0}") +MSG_DEF(JSMSG_INVALID_ARG_TYPE, 3, JSEXN_TYPEERR, "Invalid type: {0} can't be a{1} {2}") +MSG_DEF(JSMSG_TERMINATED, 1, JSEXN_ERR, "Script terminated by timeout at:\n{0}") + +// JSON +MSG_DEF(JSMSG_JSON_BAD_PARSE, 3, JSEXN_SYNTAXERR, "JSON.parse: {0} at line {1} column {2} of the JSON data") +MSG_DEF(JSMSG_JSON_CYCLIC_VALUE, 1, JSEXN_TYPEERR, "cyclic {0} value") + +// Runtime errors +MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}") +MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 0, JSEXN_REFERENCEERR, "invalid assignment left-hand side") +MSG_DEF(JSMSG_BAD_PROTOTYPE, 1, JSEXN_TYPEERR, "'prototype' property of {0} is not an object") +MSG_DEF(JSMSG_IN_NOT_OBJECT, 1, JSEXN_TYPEERR, "invalid 'in' operand {0}") +MSG_DEF(JSMSG_TOO_MANY_CON_SPREADARGS, 0, JSEXN_RANGEERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_FUN_SPREADARGS, 0, JSEXN_RANGEERR, "too many function arguments") + +// Date +MSG_DEF(JSMSG_INVALID_DATE, 0, JSEXN_RANGEERR, "invalid date") +MSG_DEF(JSMSG_BAD_TOISOSTRING_PROP, 0, JSEXN_TYPEERR, "toISOString property is not callable") + +// String +MSG_DEF(JSMSG_BAD_URI, 0, JSEXN_URIERR, "malformed URI sequence") +MSG_DEF(JSMSG_INVALID_NORMALIZE_FORM, 0, JSEXN_RANGEERR, "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'") +MSG_DEF(JSMSG_NEGATIVE_REPETITION_COUNT, 0, JSEXN_RANGEERR, "repeat count must be non-negative") +MSG_DEF(JSMSG_NOT_A_CODEPOINT, 1, JSEXN_RANGEERR, "{0} is not a valid code point") +MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size") + +// Number +MSG_DEF(JSMSG_BAD_RADIX, 0, JSEXN_RANGEERR, "radix must be an integer at least 2 and no greater than 36") +MSG_DEF(JSMSG_PRECISION_RANGE, 1, JSEXN_RANGEERR, "precision {0} out of range") + +// Function +MSG_DEF(JSMSG_BAD_APPLY_ARGS, 1, JSEXN_TYPEERR, "second argument to Function.prototype.{0} must be an array") +MSG_DEF(JSMSG_BAD_FORMAL, 0, JSEXN_SYNTAXERR, "malformed formal parameter") +MSG_DEF(JSMSG_CALLER_IS_STRICT, 0, JSEXN_TYPEERR, "access to strict mode caller function is censored") +MSG_DEF(JSMSG_DEPRECATED_USAGE, 1, JSEXN_REFERENCEERR, "deprecated {0} usage") +MSG_DEF(JSMSG_FUNCTION_ARGUMENTS_AND_REST, 0, JSEXN_TYPEERR, "the 'arguments' property of a function with a rest parameter may not be used") +MSG_DEF(JSMSG_NOT_SCRIPTED_FUNCTION, 1, JSEXN_TYPEERR, "{0} is not a scripted function") +MSG_DEF(JSMSG_NO_REST_NAME, 0, JSEXN_SYNTAXERR, "no parameter name after ...") +MSG_DEF(JSMSG_PARAMETER_AFTER_REST, 0, JSEXN_SYNTAXERR, "parameter after rest parameter") +MSG_DEF(JSMSG_TOO_MANY_FUN_APPLY_ARGS, 0, JSEXN_RANGEERR, "arguments array passed to Function.prototype.apply is too large") + +// CSP +MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 0, JSEXN_ERR, "call to eval() blocked by CSP") +MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 0, JSEXN_ERR, "call to Function() blocked by CSP") + +// Wrappers +MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property '{0}'") +MSG_DEF(JSMSG_DEAD_OBJECT, 0, JSEXN_TYPEERR, "can't access dead object") +MSG_DEF(JSMSG_UNWRAP_DENIED, 0, JSEXN_ERR, "permission denied to unwrap object") + +// JSAPI-only (Not thrown as JS exceptions) +MSG_DEF(JSMSG_BAD_CHAR, 1, JSEXN_INTERNALERR, "invalid format character {0}") +MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 0, JSEXN_TYPEERR, "bad cloned function scope chain") +MSG_DEF(JSMSG_BAD_NEW_RESULT, 1, JSEXN_TYPEERR, "invalid new expression result {0}") +MSG_DEF(JSMSG_BAD_TYPE, 1, JSEXN_TYPEERR, "unknown type {0}") +MSG_DEF(JSMSG_CANT_CLONE_OBJECT, 0, JSEXN_TYPEERR, "can't clone object") +MSG_DEF(JSMSG_CANT_OPEN, 2, JSEXN_ERR, "can't open {0}: {1}") +MSG_DEF(JSMSG_USER_DEFINED_ERROR, 0, JSEXN_ERR, "JS_ReportError was called") + +// Internal errors +MSG_DEF(JSMSG_ALLOC_OVERFLOW, 0, JSEXN_INTERNALERR, "allocation size overflow") +MSG_DEF(JSMSG_BAD_BYTECODE, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}") +MSG_DEF(JSMSG_BAD_SCRIPT_MAGIC, 0, JSEXN_INTERNALERR, "bad script XDR magic number") +MSG_DEF(JSMSG_BUFFER_TOO_SMALL, 0, JSEXN_INTERNALERR, "buffer too small") +MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})") +MSG_DEF(JSMSG_CANT_SET_ARRAY_ATTRS, 0, JSEXN_INTERNALERR, "can't set attributes on indexed array properties") +MSG_DEF(JSMSG_INACTIVE, 0, JSEXN_INTERNALERR, "nothing active on context") +MSG_DEF(JSMSG_NEED_DIET, 1, JSEXN_INTERNALERR, "{0} too large") +MSG_DEF(JSMSG_OUT_OF_MEMORY, 0, JSEXN_INTERNALERR, "out of memory") +MSG_DEF(JSMSG_OVER_RECURSED, 0, JSEXN_INTERNALERR, "too much recursion") +MSG_DEF(JSMSG_TOO_BIG_TO_ENCODE, 0, JSEXN_INTERNALERR, "data are to big to encode") +MSG_DEF(JSMSG_TOO_DEEP, 1, JSEXN_INTERNALERR, "{0} nested too deeply") +MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 1, JSEXN_INTERNALERR, "uncaught exception: {0}") +MSG_DEF(JSMSG_UNKNOWN_FORMAT, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}") + +// Frontend +MSG_DEF(JSMSG_ACCESSOR_WRONG_ARGS, 3, JSEXN_SYNTAXERR, "{0} functions must have {1} argument{2}") +MSG_DEF(JSMSG_ARGUMENTS_AND_REST, 0, JSEXN_SYNTAXERR, "'arguments' object may not be used in conjunction with a rest parameter") +MSG_DEF(JSMSG_ARRAY_COMP_LEFTSIDE, 0, JSEXN_SYNTAXERR, "invalid array comprehension left-hand side") +MSG_DEF(JSMSG_ARRAY_INIT_TOO_BIG, 0, JSEXN_INTERNALERR, "array initialiser too large") +MSG_DEF(JSMSG_AS_AFTER_RESERVED_WORD, 1, JSEXN_SYNTAXERR, "missing keyword 'as' after reserved word '{0}'") +MSG_DEF(JSMSG_BAD_ANON_GENERATOR_RETURN, 0, JSEXN_TYPEERR, "anonymous generator function returns a value") +MSG_DEF(JSMSG_BAD_ARROW_ARGS, 0, JSEXN_SYNTAXERR, "invalid arrow-function arguments (parentheses around the arrow-function may help)") +MSG_DEF(JSMSG_BAD_BINDING, 1, JSEXN_SYNTAXERR, "redefining {0} is deprecated") +MSG_DEF(JSMSG_BAD_CONTINUE, 0, JSEXN_SYNTAXERR, "continue must be inside loop") +MSG_DEF(JSMSG_BAD_DESTRUCT_ASS, 0, JSEXN_REFERENCEERR, "invalid destructuring assignment operator") +MSG_DEF(JSMSG_BAD_DESTRUCT_TARGET, 0, JSEXN_SYNTAXERR, "invalid destructuring target") +MSG_DEF(JSMSG_BAD_DESTRUCT_DECL, 0, JSEXN_SYNTAXERR, "missing = in destructuring declaration") +MSG_DEF(JSMSG_BAD_DUP_ARGS, 0, JSEXN_SYNTAXERR, "duplicate argument names not allowed in this context") +MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 0, JSEXN_SYNTAXERR, "invalid for each loop") +MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side") +MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 1, JSEXN_TYPEERR, "generator function {0} returns a value") +MSG_DEF(JSMSG_BAD_GENERATOR_SYNTAX, 1, JSEXN_SYNTAXERR, "{0} expression must be parenthesized") +MSG_DEF(JSMSG_BAD_GENEXP_BODY, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression") +MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand") +MSG_DEF(JSMSG_BAD_OCTAL, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant") +MSG_DEF(JSMSG_BAD_OPERAND, 1, JSEXN_SYNTAXERR, "invalid {0} operand") +MSG_DEF(JSMSG_BAD_PROP_ID, 0, JSEXN_SYNTAXERR, "invalid property id") +MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 1, JSEXN_SYNTAXERR, "{0} not in function") +MSG_DEF(JSMSG_BAD_STRICT_ASSIGN, 1, JSEXN_SYNTAXERR, "can't assign to {0} in strict mode") +MSG_DEF(JSMSG_BAD_SWITCH, 0, JSEXN_SYNTAXERR, "invalid switch statement") +MSG_DEF(JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION, 0, JSEXN_SYNTAXERR, "missing ] after array comprehension") +MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 0, JSEXN_SYNTAXERR, "missing ] after element list") +MSG_DEF(JSMSG_BRACKET_IN_INDEX, 0, JSEXN_SYNTAXERR, "missing ] in index expression") +MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 0, JSEXN_SYNTAXERR, "catch after unconditional catch") +MSG_DEF(JSMSG_CATCH_IDENTIFIER, 0, JSEXN_SYNTAXERR, "missing identifier in catch") +MSG_DEF(JSMSG_CATCH_OR_FINALLY, 0, JSEXN_SYNTAXERR, "missing catch or finally after try") +MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 0, JSEXN_SYNTAXERR, "catch without try") +MSG_DEF(JSMSG_COLON_AFTER_CASE, 0, JSEXN_SYNTAXERR, "missing : after case label") +MSG_DEF(JSMSG_COLON_AFTER_ID, 0, JSEXN_SYNTAXERR, "missing : after property id") +MSG_DEF(JSMSG_COLON_IN_COND, 0, JSEXN_SYNTAXERR, "missing : in conditional expression") +MSG_DEF(JSMSG_COMP_PROP_UNTERM_EXPR, 0, JSEXN_SYNTAXERR, "missing ] in computed property name") +MSG_DEF(JSMSG_CONTRARY_NONDIRECTIVE, 1, JSEXN_SYNTAXERR, "'{0}' statement won't be enforced as a directive because it isn't in directive prologue position") +MSG_DEF(JSMSG_CURLY_AFTER_BODY, 0, JSEXN_SYNTAXERR, "missing } after function body") +MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 0, JSEXN_SYNTAXERR, "missing } after catch block") +MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 0, JSEXN_SYNTAXERR, "missing } after finally block") +MSG_DEF(JSMSG_CURLY_AFTER_LET, 0, JSEXN_SYNTAXERR, "missing } after let block") +MSG_DEF(JSMSG_CURLY_AFTER_LIST, 0, JSEXN_SYNTAXERR, "missing } after property list") +MSG_DEF(JSMSG_CURLY_AFTER_TRY, 0, JSEXN_SYNTAXERR, "missing } after try block") +MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 0, JSEXN_SYNTAXERR, "missing { before function body") +MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 0, JSEXN_SYNTAXERR, "missing { before catch block") +MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 0, JSEXN_SYNTAXERR, "missing { before finally block") +MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 0, JSEXN_SYNTAXERR, "missing { before switch body") +MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 0, JSEXN_SYNTAXERR, "missing { before try block") +MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 0, JSEXN_SYNTAXERR, "missing } in compound statement") +MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT,0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") +MSG_DEF(JSMSG_DECLARATION_AFTER_IMPORT,0, JSEXN_SYNTAXERR, "missing declaration after 'import' keyword") +MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 0, JSEXN_SYNTAXERR, "applying the 'delete' operator to an unqualified name is deprecated") +MSG_DEF(JSMSG_DEPRECATED_OCTAL, 0, JSEXN_SYNTAXERR, "octal literals and octal escape sequences are deprecated") +MSG_DEF(JSMSG_DEPRECATED_PRAGMA, 1, JSEXN_NONE, "Using //@ to indicate {0} pragmas is deprecated. Use //# instead") +MSG_DEF(JSMSG_DUPLICATE_FORMAL, 1, JSEXN_SYNTAXERR, "duplicate formal argument {0}") +MSG_DEF(JSMSG_DUPLICATE_LABEL, 0, JSEXN_SYNTAXERR, "duplicate label") +MSG_DEF(JSMSG_DUPLICATE_PROPERTY, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal") +MSG_DEF(JSMSG_EMPTY_CONSEQUENT, 0, JSEXN_SYNTAXERR, "mistyped ; after conditional?") +MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 0, JSEXN_SYNTAXERR, "test for equality (==) mistyped as assignment (=)?") +MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL,0, JSEXN_SYNTAXERR, "export declarations may only appear at top level") +MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 0, JSEXN_SYNTAXERR, "finally without try") +MSG_DEF(JSMSG_FROM_AFTER_IMPORT_SPEC_SET, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after import specifier set") +MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal") +MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 0, JSEXN_SYNTAXERR, "illegal character") +MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level") +MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 0, JSEXN_SYNTAXERR, "for-in loop let declaration may not have an initializer") +MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer") +MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") +MSG_DEF(JSMSG_LABEL_NOT_FOUND, 0, JSEXN_SYNTAXERR, "label not found") +MSG_DEF(JSMSG_LET_COMP_BINDING, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a comprehension variable") +MSG_DEF(JSMSG_LET_DECL_NOT_IN_BLOCK, 0, JSEXN_SYNTAXERR, "let declaration not directly within block") +MSG_DEF(JSMSG_MALFORMED_ESCAPE, 1, JSEXN_SYNTAXERR, "malformed {0} character escape sequence") +MSG_DEF(JSMSG_MISSING_BINARY_DIGITS, 0, JSEXN_SYNTAXERR, "missing binary digits after '0b'") +MSG_DEF(JSMSG_MISSING_EXPONENT, 0, JSEXN_SYNTAXERR, "missing exponent") +MSG_DEF(JSMSG_MISSING_FORMAL, 0, JSEXN_SYNTAXERR, "missing formal parameter") +MSG_DEF(JSMSG_MISSING_HEXDIGITS, 0, JSEXN_SYNTAXERR, "missing hexadecimal digits after '0x'") +MSG_DEF(JSMSG_MISSING_OCTAL_DIGITS, 0, JSEXN_SYNTAXERR, "missing octal digits after '0o'") +MSG_DEF(JSMSG_MODULES_NOT_IMPLEMENTED, 0, JSEXN_SYNTAXERR, "modules are not implemented yet") +MSG_DEF(JSMSG_MODULE_SPEC_AFTER_FROM, 0, JSEXN_SYNTAXERR, "missing module specifier after 'from' keyword") +MSG_DEF(JSMSG_NAME_AFTER_DOT, 0, JSEXN_SYNTAXERR, "missing name after . operator") +MSG_DEF(JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT, 0, JSEXN_SYNTAXERR, "parameter(s) with default followed by parameter without default") +MSG_DEF(JSMSG_NO_BINDING_NAME, 0, JSEXN_SYNTAXERR, "missing binding name") +MSG_DEF(JSMSG_NO_EXPORT_NAME, 0, JSEXN_SYNTAXERR, "missing export name") +MSG_DEF(JSMSG_NO_IMPORT_NAME, 0, JSEXN_SYNTAXERR, "missing import name") +MSG_DEF(JSMSG_NO_VARIABLE_NAME, 0, JSEXN_SYNTAXERR, "missing variable name") +MSG_DEF(JSMSG_OF_AFTER_FOR_NAME, 0, JSEXN_SYNTAXERR, "missing 'of' after for") +MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 0, JSEXN_SYNTAXERR, "missing ) after argument list") +MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 0, JSEXN_SYNTAXERR, "missing ) after catch") +MSG_DEF(JSMSG_PAREN_AFTER_COND, 0, JSEXN_SYNTAXERR, "missing ) after condition") +MSG_DEF(JSMSG_PAREN_AFTER_FOR, 0, JSEXN_SYNTAXERR, "missing ( after for") +MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control") +MSG_DEF(JSMSG_PAREN_AFTER_FOR_OF_ITERABLE, 0, JSEXN_SYNTAXERR, "missing ) after for-of iterable") +MSG_DEF(JSMSG_PAREN_AFTER_LET, 0, JSEXN_SYNTAXERR, "missing ) after let head") +MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 0, JSEXN_SYNTAXERR, "missing ) after switch expression") +MSG_DEF(JSMSG_PAREN_AFTER_WITH, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object") +MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 0, JSEXN_SYNTAXERR, "missing ( before catch") +MSG_DEF(JSMSG_PAREN_BEFORE_COND, 0, JSEXN_SYNTAXERR, "missing ( before condition") +MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters") +MSG_DEF(JSMSG_PAREN_BEFORE_LET, 0, JSEXN_SYNTAXERR, "missing ( before let head") +MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 0, JSEXN_SYNTAXERR, "missing ( before switch expression") +MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object") +MSG_DEF(JSMSG_PAREN_IN_PAREN, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical") +MSG_DEF(JSMSG_RC_AFTER_EXPORT_SPEC_LIST, 0, JSEXN_SYNTAXERR, "missing '}' after export specifier list") +MSG_DEF(JSMSG_RC_AFTER_IMPORT_SPEC_LIST, 0, JSEXN_SYNTAXERR, "missing '}' after module specifier list") +MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 1, JSEXN_TYPEERR, "redeclaration of identifier '{0}' in catch") +MSG_DEF(JSMSG_REDECLARED_PARAM, 1, JSEXN_TYPEERR, "redeclaration of formal parameter {0}") +MSG_DEF(JSMSG_RESERVED_ID, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier") +MSG_DEF(JSMSG_REST_WITH_DEFAULT, 0, JSEXN_SYNTAXERR, "rest parameter may not have a default") +MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LET,0, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level 'let' declarations") +MSG_DEF(JSMSG_SELFHOSTED_UNBOUND_NAME, 0, JSEXN_TYPEERR, "self-hosted code may not contain unbound name lookups") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition") +MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer") +MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 0, JSEXN_SYNTAXERR, "missing ; before statement") +MSG_DEF(JSMSG_SOURCE_TOO_LONG, 0, JSEXN_RANGEERR, "source is too long") +MSG_DEF(JSMSG_STRICT_CODE_LET_EXPR_STMT, 0, JSEXN_ERR, "strict mode code may not contain unparenthesized let expression statements") +MSG_DEF(JSMSG_STRICT_CODE_WITH, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements") +MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function") +MSG_DEF(JSMSG_SYNTAX_ERROR, 0, JSEXN_SYNTAXERR, "syntax error") +MSG_DEF(JSMSG_TEMPLSTR_UNTERM_EXPR, 0, JSEXN_SYNTAXERR, "missing } in template string") +MSG_DEF(JSMSG_SIMD_NOT_A_VECTOR, 0, JSEXN_TYPEERR, "value isn't a SIMD value object") +MSG_DEF(JSMSG_TOO_MANY_CASES, 0, JSEXN_INTERNALERR, "too many switch cases") +MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 0, JSEXN_SYNTAXERR, "too many catch variables") +MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 0, JSEXN_SYNTAXERR, "too many constructor arguments") +MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 0, JSEXN_SYNTAXERR, "more than one switch default") +MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 0, JSEXN_SYNTAXERR, "too many function arguments") +MSG_DEF(JSMSG_TOO_MANY_LOCALS, 0, JSEXN_SYNTAXERR, "too many local variables") +MSG_DEF(JSMSG_TOUGH_BREAK, 0, JSEXN_SYNTAXERR, "unlabeled break must be inside loop or switch") +MSG_DEF(JSMSG_UNNAMED_FUNCTION_STMT, 0, JSEXN_SYNTAXERR, "function statement requires a name") +MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 0, JSEXN_SYNTAXERR, "unterminated comment") +MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal") +MSG_DEF(JSMSG_UNTERMINATED_STRING, 0, JSEXN_SYNTAXERR, "unterminated string literal") +MSG_DEF(JSMSG_USELESS_EXPR, 0, JSEXN_TYPEERR, "useless expression") +MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body") +MSG_DEF(JSMSG_VAR_HIDES_ARG, 1, JSEXN_TYPEERR, "variable {0} redeclares argument") +MSG_DEF(JSMSG_WHILE_AFTER_DO, 0, JSEXN_SYNTAXERR, "missing while after do-loop body") +MSG_DEF(JSMSG_YIELD_IN_ARROW, 0, JSEXN_SYNTAXERR, "arrow function may not contain yield") +MSG_DEF(JSMSG_YIELD_IN_DEFAULT, 0, JSEXN_SYNTAXERR, "yield in default expression") + +// asm.js +MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL, 1, JSEXN_TYPEERR, "asm.js type error: {0}") +MSG_DEF(JSMSG_USE_ASM_LINK_FAIL, 1, JSEXN_TYPEERR, "asm.js link error: {0}") +MSG_DEF(JSMSG_USE_ASM_TYPE_OK, 1, JSEXN_NONE, "Successfully compiled asm.js code ({0})") + +// Proxy +MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE, 2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value") +MSG_DEF(JSMSG_CANT_CHANGE_EXTENSIBILITY, 0, JSEXN_TYPEERR, "can't change object's extensibility") +MSG_DEF(JSMSG_CANT_DEFINE_INVALID, 0, JSEXN_TYPEERR, "proxy can't define an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_DEFINE_NEW, 0, JSEXN_TYPEERR, "proxy can't define a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_DEFINE_NE_AS_NC, 0, JSEXN_TYPEERR, "proxy can't define a non-existent property as non-configurable") +MSG_DEF(JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE, 0, JSEXN_TYPEERR, "proxy can't report an extensible object as non-extensible") +MSG_DEF(JSMSG_CANT_REPORT_C_AS_NC, 0, JSEXN_TYPEERR, "proxy can't report existing configurable property as non-configurable") +MSG_DEF(JSMSG_CANT_REPORT_E_AS_NE, 0, JSEXN_TYPEERR, "proxy can't report an existing own property as non-existent on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_INVALID, 0, JSEXN_TYPEERR, "proxy can't report an incompatible property descriptor") +MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") +MSG_DEF(JSMSG_CANT_REPORT_NEW, 0, JSEXN_TYPEERR, "proxy can't report a new property on a non-extensible object") +MSG_DEF(JSMSG_CANT_REPORT_NE_AS_NC, 0, JSEXN_TYPEERR, "proxy can't report a non-existent property as non-configurable") +MSG_DEF(JSMSG_CANT_SET_NW_NC, 0, JSEXN_TYPEERR, "proxy can't successfully set a non-writable, non-configurable property") +MSG_DEF(JSMSG_CANT_SET_WO_SETTER, 0, JSEXN_TYPEERR, "proxy can't succesfully set an accessor property without a setter") +MSG_DEF(JSMSG_CANT_SKIP_NC, 0, JSEXN_TYPEERR, "proxy can't skip a non-configurable property") +MSG_DEF(JSMSG_INVALID_TRAP_RESULT, 2, JSEXN_TYPEERR, "trap {1} for {0} returned an invalid result") +MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property") +MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter") +MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object") +MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property '{0}'") +MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") +MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") +MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") +MSG_DEF(JSMSG_PROXY_REVOKED, 0, JSEXN_TYPEERR, "illegal operation attempted on a revoked proxy") + +// Structured cloning +MSG_DEF(JSMSG_SC_BAD_CLONE_VERSION, 0, JSEXN_ERR, "unsupported structured clone version") +MSG_DEF(JSMSG_SC_BAD_SERIALIZED_DATA, 1, JSEXN_INTERNALERR, "bad serialized structured data ({0})") +MSG_DEF(JSMSG_SC_DUP_TRANSFERABLE, 0, JSEXN_TYPEERR, "duplicate transferable for structured clone") +MSG_DEF(JSMSG_SC_NOT_TRANSFERABLE, 0, JSEXN_TYPEERR, "invalid transferable array for structured clone") +MSG_DEF(JSMSG_SC_UNSUPPORTED_TYPE, 0, JSEXN_TYPEERR, "unsupported type for structured data") + +// Debugger +MSG_DEF(JSMSG_ASSIGN_FUNCTION_OR_NULL, 1, JSEXN_TYPEERR, "value assigned to {0} must be a function or null") +MSG_DEF(JSMSG_DEBUG_BAD_LINE, 0, JSEXN_TYPEERR, "invalid line number") +MSG_DEF(JSMSG_DEBUG_BAD_OFFSET, 0, JSEXN_TYPEERR, "invalid script offset") +MSG_DEF(JSMSG_DEBUG_BAD_REFERENT, 2, JSEXN_TYPEERR, "{0} does not refer to {1}") +MSG_DEF(JSMSG_DEBUG_BAD_RESUMPTION, 0, JSEXN_TYPEERR, "debugger resumption value must be undefined, {throw: val}, {return: val}, or null") +MSG_DEF(JSMSG_DEBUG_CANT_DEBUG_GLOBAL, 0, JSEXN_ERR, "passing non-debuggable global to addDebuggee") +MSG_DEF(JSMSG_DEBUG_CCW_REQUIRED, 1, JSEXN_TYPEERR, "{0}: argument must be an object from a different compartment") +MSG_DEF(JSMSG_DEBUG_COMPARTMENT_MISMATCH, 2, JSEXN_TYPEERR, "{0}: descriptor .{1} property is an object in a different compartment than the target object") +MSG_DEF(JSMSG_DEBUG_LOOP, 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_DEBUGGEE, 2, JSEXN_ERR, "{0} is not a debuggee {1}") +MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGING, 0, JSEXN_ERR, "can't set breakpoint: script global is not a debuggee") +MSG_DEF(JSMSG_DEBUG_NOT_IDLE, 0, JSEXN_ERR, "can't start debugging: a debuggee script is on the stack") +MSG_DEF(JSMSG_DEBUG_NOT_LIVE, 1, JSEXN_ERR, "{0} is not live") +MSG_DEF(JSMSG_DEBUG_NO_SCOPE_OBJECT, 0, JSEXN_TYPEERR, "declarative Environments don't have binding objects") +MSG_DEF(JSMSG_DEBUG_OBJECT_PROTO, 0, JSEXN_TYPEERR, "Debugger.Object.prototype is not a valid Debugger.Object") +MSG_DEF(JSMSG_DEBUG_OBJECT_WRONG_OWNER,0, JSEXN_TYPEERR, "Debugger.Object belongs to a different Debugger") +MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 0, JSEXN_ERR, "variable has been optimized out") +MSG_DEF(JSMSG_DEBUG_RESUMPTION_VALUE_DISALLOWED, 0, JSEXN_TYPEERR, "resumption values are disallowed in this hook") +MSG_DEF(JSMSG_DEBUG_VARIABLE_NOT_FOUND,0, JSEXN_TYPEERR, "variable not found in environment") +MSG_DEF(JSMSG_DEBUG_WRAPPER_IN_WAY, 3, JSEXN_TYPEERR, "{0} is {1}{2}a global object, but a direct reference is required") +MSG_DEF(JSMSG_NOT_CALLABLE_OR_UNDEFINED, 0, JSEXN_TYPEERR, "value is not a function or undefined") +MSG_DEF(JSMSG_NOT_TRACKING_ALLOCATIONS, 1, JSEXN_ERR, "Cannot call {0} without setting trackingAllocationSites to true") +MSG_DEF(JSMSG_OBJECT_METADATA_CALLBACK_ALREADY_SET, 0, JSEXN_ERR, "Cannot track object allocation, because other tools are already doing so") +MSG_DEF(JSMSG_QUERY_INNERMOST_WITHOUT_LINE_URL, 0, JSEXN_TYPEERR, "findScripts query object with 'innermost' property must have 'line' and either 'displayURL', 'url', or 'source'") +MSG_DEF(JSMSG_QUERY_LINE_WITHOUT_URL, 0, JSEXN_TYPEERR, "findScripts query object has 'line' property, but no 'displayURL', 'url', or 'source' property") + +// Intl +MSG_DEF(JSMSG_DATE_NOT_FINITE, 0, JSEXN_RANGEERR, "date value is not finite in DateTimeFormat.format()") +MSG_DEF(JSMSG_INTERNAL_INTL_ERROR, 0, JSEXN_ERR, "internal error while computing Intl data") +MSG_DEF(JSMSG_INTL_OBJECT_NOT_INITED, 3, JSEXN_TYPEERR, "Intl.{0}.prototype.{1} called on value that's not an object initialized as a {2}") +MSG_DEF(JSMSG_INTL_OBJECT_REINITED, 0, JSEXN_TYPEERR, "can't initialize object twice as an object of an Intl constructor") +MSG_DEF(JSMSG_INVALID_CURRENCY_CODE, 1, JSEXN_RANGEERR, "invalid currency code in NumberFormat(): {0}") +MSG_DEF(JSMSG_INVALID_DIGITS_VALUE, 1, JSEXN_RANGEERR, "invalid digits value: {0}") +MSG_DEF(JSMSG_INVALID_LANGUAGE_TAG, 1, JSEXN_RANGEERR, "invalid language tag: {0}") +MSG_DEF(JSMSG_INVALID_LOCALES_ELEMENT, 0, JSEXN_TYPEERR, "invalid element in locales argument") +MSG_DEF(JSMSG_INVALID_LOCALE_MATCHER, 1, JSEXN_RANGEERR, "invalid locale matcher in supportedLocalesOf(): {0}") +MSG_DEF(JSMSG_INVALID_OPTION_VALUE, 2, JSEXN_RANGEERR, "invalid value {1} for option {0}") +MSG_DEF(JSMSG_INVALID_TIME_ZONE, 1, JSEXN_RANGEERR, "invalid time zone in DateTimeFormat(): {0}") +MSG_DEF(JSMSG_UNDEFINED_CURRENCY, 0, JSEXN_TYPEERR, "undefined currency in NumberFormat() with currency style") + +// RegExp +MSG_DEF(JSMSG_BAD_CLASS_RANGE, 0, JSEXN_SYNTAXERR, "invalid range in character class") +MSG_DEF(JSMSG_ESCAPE_AT_END_OF_REGEXP, 0, JSEXN_SYNTAXERR, "\\ at end of pattern") +MSG_DEF(JSMSG_INVALID_GROUP, 0, JSEXN_SYNTAXERR, "invalid regexp group") +MSG_DEF(JSMSG_MISSING_PAREN, 0, JSEXN_SYNTAXERR, "unterminated parenthetical") +MSG_DEF(JSMSG_NEWREGEXP_FLAGGED, 0, JSEXN_TYPEERR, "can't supply flags when constructing one RegExp from another") +MSG_DEF(JSMSG_NOTHING_TO_REPEAT, 0, JSEXN_SYNTAXERR, "nothing to repeat") +MSG_DEF(JSMSG_NUMBERS_OUT_OF_ORDER, 0, JSEXN_SYNTAXERR, "numbers out of order in {} quantifier.") +MSG_DEF(JSMSG_TOO_MANY_PARENS, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression") +MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression") +MSG_DEF(JSMSG_UNTERM_CLASS, 0, JSEXN_SYNTAXERR, "unterminated character class") + +// Self-hosting +MSG_DEF(JSMSG_DEFAULT_LOCALE_ERROR, 0, JSEXN_ERR, "internal error getting the default locale") +MSG_DEF(JSMSG_NO_SUCH_SELF_HOSTED_PROP,1, JSEXN_ERR, "No such property on self-hosted object: {0}") + +// Typed object +MSG_DEF(JSMSG_INVALID_PROTOTYPE, 0, JSEXN_TYPEERR, "prototype field is not an object") +MSG_DEF(JSMSG_TYPEDOBJECT_ARRAYTYPE_BAD_ARGS, 0, JSEXN_ERR, "Invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_BAD_ARGS, 0, JSEXN_TYPEERR, "invalid arguments") +MSG_DEF(JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED, 0, JSEXN_TYPEERR, "handle unattached") +MSG_DEF(JSMSG_TYPEDOBJECT_STRUCTTYPE_BAD_ARGS, 0, JSEXN_RANGEERR, "invalid field descriptor") +MSG_DEF(JSMSG_TYPEDOBJECT_TOO_BIG, 0, JSEXN_ERR, "Type is too large to allocate") + +// Typed array +MSG_DEF(JSMSG_BAD_INDEX, 0, JSEXN_RANGEERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 0, JSEXN_ERR, "invalid arguments") +MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 0, JSEXN_ERR, "invalid or out-of-range index") +MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG,1, JSEXN_ERR, "argument {0} must be >= 0") + +// Parallel array +MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 0, JSEXN_RANGEERR, "invalid parallel method argument") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BAD_TARGET, 1, JSEXN_ERR, "target for index {0} is not an integer") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS,0, JSEXN_ERR, "index in scatter vector out of bounds") +MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 0, JSEXN_ERR, "no conflict resolution function provided") + +// Reflect +MSG_DEF(JSMSG_BAD_PARSE_NODE, 0, JSEXN_INTERNALERR, "bad parse node") -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") +// Symbol +MSG_DEF(JSMSG_BAD_SYMBOL, 1, JSEXN_TYPEERR, "{0} is not a well-known @@-symbol") +MSG_DEF(JSMSG_SYMBOL_TO_STRING, 0, JSEXN_TYPEERR, "can't convert symbol to string") +MSG_DEF(JSMSG_SYMBOL_TO_NUMBER, 0, JSEXN_TYPEERR, "can't convert symbol to number") 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..153441d98a 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 @@ -362,6 +362,13 @@ class MOZ_STACK_CLASS CallArgs : public detail::CallArgsBase 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..0a616c3aae 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; @@ -662,8 +522,9 @@ Valueify(const JSClass *c) * value of objects. */ enum ESClassValue { - ESClass_Array, ESClass_Number, ESClass_String, ESClass_Boolean, - ESClass_RegExp, ESClass_ArrayBuffer, ESClass_Date + ESClass_Object, ESClass_Array, ESClass_Number, ESClass_String, + ESClass_Boolean, ESClass_RegExp, ESClass_ArrayBuffer, ESClass_Date, + ESClass_Set, ESClass_Map }; /* @@ -679,20 +540,9 @@ ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx); inline bool IsObjectWithClass(const JS::Value &v, ESClassValue classValue, JSContext *cx); +/* Fills |vp| with the unboxed value for boxed types, or undefined otherwise. */ 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); } -}; +Unbox(JSContext *cx, JS::HandleObject obj, JS::MutableHandleValue vp); } /* namespace js */ diff --git a/frameworks/js-bindings/external/spidermonkey/include/ios/js/DebugAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/DebugAPI.h new file mode 100644 index 0000000000..6cac090fcd --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/DebugAPI.h @@ -0,0 +1,256 @@ +/* -*- 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/. */ + +// Interfaces by which the embedding can interact with the Debugger API. + +#ifndef js_DebugAPI_h +#define js_DebugAPI_h + +#include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" + +#include "jspubtd.h" + +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" + +namespace js { +class Debugger; +} + +namespace JS { +namespace dbg { + +// Helping embedding code build objects for Debugger +// ------------------------------------------------- +// +// Some Debugger API features lean on the embedding application to construct +// their result values. For example, Debugger.Frame.prototype.scriptEntryReason +// calls hooks provided by the embedding to construct values explaining why it +// invoked JavaScript; if F is a frame called from a mouse click event handler, +// F.scriptEntryReason would return an object of the form: +// +// { eventType: "mousedown", event: } +// +// where is a Debugger.Object whose referent is the event being +// dispatched. +// +// However, Debugger implements a trust boundary. Debuggee code may be +// considered untrusted; debugger code needs to be protected from debuggee +// getters, setters, proxies, Object.watch watchpoints, and any other feature +// that might accidentally cause debugger code to set the debuggee running. The +// Debugger API tries to make it easy to write safe debugger code by only +// offering access to debuggee objects via Debugger.Object instances, which +// ensure that only those operations whose explicit purpose is to invoke +// debuggee code do so. But this protective membrane is only helpful if we +// interpose Debugger.Object instances in all the necessary spots. +// +// SpiderMonkey's compartment system also implements a trust boundary. The +// debuggee and debugger are always in different compartments. Inter-compartment +// work requires carefully tracking which compartment each JSObject or JS::Value +// belongs to, and ensuring that is is correctly wrapped for each operation. +// +// It seems precarious to expect the embedding's hooks to implement these trust +// boundaries. Instead, the JS::dbg::Builder API segregates the code which +// constructs trusted objects from that which deals with untrusted objects. +// Trusted objects have an entirely different C++ type, so code that improperly +// mixes trusted and untrusted objects is caught at compile time. +// +// In the structure shown above, there are two trusted objects, and one +// untrusted object: +// +// - The overall object, with the 'eventType' and 'event' properties, is a +// trusted object. We're going to return it to D.F.p.scriptEntryReason's +// caller, which will handle it directly. +// +// - The Debugger.Object instance appearing as the value of the 'event' property +// is a trusted object. It belongs to the same Debugger instance as the +// Debugger.Frame instance whose scriptEntryReason accessor was called, and +// presents a safe reflection-oriented API for inspecting its referent, which +// is: +// +// - The actual event object, an untrusted object, and the referent of the +// Debugger.Object above. (Content can do things like replacing accessors on +// Event.prototype.) +// +// Using JS::dbg::Builder, all objects and values the embedding deals with +// directly are considered untrusted, and are assumed to be debuggee values. The +// only way to construct trusted objects is to use Builder's own methods, which +// return a separate Object type. The only way to set a property on a trusted +// object is through that Object type. The actual trusted object is never +// exposed to the embedding. +// +// So, for example, the embedding might use code like the following to construct +// the object shown above, given a Builder passed to it by Debugger: +// +// bool +// MyScriptEntryReason::explain(JSContext *cx, +// Builder &builder, +// Builder::Object &result) +// { +// JSObject *eventObject = ... obtain debuggee event object somehow ...; +// if (!eventObject) +// return false; +// result = builder.newObject(cx); +// return result && +// result.defineProperty(cx, "eventType", SafelyFetchType(eventObject)) && +// result.defineProperty(cx, "event", eventObject); +// } +// +// +// Object::defineProperty also accepts an Object as the value to store on the +// property. By its type, we know that the value is trusted, so we set it +// directly as the property's value, without interposing a Debugger.Object +// wrapper. This allows the embedding to builted nested structures of trusted +// objects. +// +// The Builder and Builder::Object methods take care of doing whatever +// compartment switching and wrapping are necessary to construct the trusted +// values in the Debugger's compartment. +// +// The Object type is self-rooting. Construction, assignment, and destruction +// all properly root the referent object. + +class BuilderOrigin; + +class Builder { + // The Debugger instance whose client we are building a value for. We build + // objects in this object's compartment. + PersistentRootedObject debuggerObject; + + // debuggerObject's Debugger structure, for convenience. + js::Debugger *debugger; + + // Check that |thing| is in the same compartment as our debuggerObject. Used + // for assertions when constructing BuiltThings. We can overload this as we + // add more instantiations of BuiltThing. +#if DEBUG + void assertBuilt(JSObject *obj); +#else + void assertBuilt(JSObject *obj) { } +#endif + + protected: + // A reference to a trusted object or value. At the moment, we only use it + // with JSObject *. + template + class BuiltThing { + friend class BuilderOrigin; + + void nonNull() {} + + protected: + // The Builder to which this trusted thing belongs. + Builder &owner; + + // A rooted reference to our value. + PersistentRooted value; + + BuiltThing(JSContext *cx, Builder &owner_, T value_ = js::GCMethods::initial()) + : owner(owner_), value(cx, value_) + { + owner.assertBuilt(value_); + } + + // Forward some things from our owner, for convenience. + js::Debugger *debugger() const { return owner.debugger; } + JSObject *debuggerObject() const { return owner.debuggerObject; } + + public: + BuiltThing(const BuiltThing &rhs) : owner(rhs.owner), value(rhs.value) { } + BuiltThing &operator=(const BuiltThing &rhs) { + MOZ_ASSERT(&owner == &rhs.owner); + owner.assertBuilt(rhs.value); + value = rhs.value; + return *this; + } + + typedef void (BuiltThing::* ConvertibleToBool)(); + operator ConvertibleToBool() const { + // If we ever instantiate BuiltThink, this might not suffice. + return value ? &BuiltThing::nonNull : 0; + } + + private: + BuiltThing() MOZ_DELETE; + }; + + public: + // A reference to a trusted object, possibly null. Instances of Object are + // always properly rooted. They can be copied and assigned, as if they were + // pointers. + class Object: private BuiltThing { + friend class Builder; // for construction + friend class BuilderOrigin; // for unwrapping + + typedef BuiltThing Base; + + // This is private, because only Builders can create Objects that + // actually point to something (hence the 'friend' declaration). + Object(JSContext *cx, Builder &owner_, HandleObject obj) : Base(cx, owner_, obj.get()) { } + + bool definePropertyToTrusted(JSContext *cx, const char *name, + JS::MutableHandleValue value); + + public: + Object(JSContext *cx, Builder &owner_) : Base(cx, owner_, nullptr) { } + Object(const Object &rhs) : Base(rhs) { } + + // Our automatically-generated assignment operator can see our base + // class's assignment operator, so we don't need to write one out here. + + // Set the property named |name| on this object to |value|. + // + // If |value| is a string or primitive, re-wrap it for the debugger's + // compartment. + // + // If |value| is an object, assume it is a debuggee object and make a + // Debugger.Object instance referring to it. Set that as the propery's + // value. + // + // If |value| is another trusted object, store it directly as the + // property's value. + // + // On error, report the problem on cx and return false. + bool defineProperty(JSContext *cx, const char *name, JS::HandleValue value); + bool defineProperty(JSContext *cx, const char *name, JS::HandleObject value); + bool defineProperty(JSContext *cx, const char *name, Object &value); + + using Base::ConvertibleToBool; + using Base::operator ConvertibleToBool; + }; + + // Build an empty object for direct use by debugger code, owned by this + // Builder. If an error occurs, report it on cx and return a false Object. + Object newObject(JSContext *cx); + + protected: + Builder(JSContext *cx, js::Debugger *debugger); +}; + +// Debugger itself instantiates this subclass of Builder, which can unwrap +// BuiltThings that belong to it. +class BuilderOrigin : public Builder { + template + T unwrapAny(const BuiltThing &thing) { + MOZ_ASSERT(&thing.owner == this); + return thing.value.get(); + } + + public: + BuilderOrigin(JSContext *cx, js::Debugger *debugger_) + : Builder(cx, debugger_) + { } + + JSObject *unwrap(Object &object) { return unwrapAny(object); } +}; + +} // namespace dbg +} // namespace JS + + +#endif /* js_DebugAPI_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..8cdcfe99e3 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 { @@ -25,7 +43,7 @@ namespace JS { D(TOO_MUCH_MALLOC) \ D(ALLOC_TRIGGER) \ D(DEBUG_GC) \ - D(TRANSPLANT) \ + D(COMPARTMENT_REVIVED) \ D(RESET) \ D(OUT_OF_NURSERY) \ D(EVICT_NURSERY) \ @@ -72,7 +90,7 @@ namespace JS { D(REFRESH_FRAME) \ D(FULL_GC_TIMER) \ D(SHUTDOWN_CC) \ - D(FINISH_LARGE_EVALUTE) + D(FINISH_LARGE_EVALUATE) namespace gcreason { @@ -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) {} }; /* @@ -278,50 +437,59 @@ class JS_PUBLIC_API(ObjectPtr) 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 JS_ALWAYS_INLINE void +} /* namespace JS */ + +namespace js { +namespace gc { + +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); + JS::shadow::Runtime *rt = 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(rt, thing)) + if (IsInsideNursery((Cell *)thing)) return; #endif - if (IsIncrementalBarrierNeededOnGCThing(rt, thing, kind)) - IncrementalReferenceBarrier(thing, kind); - else if (GCThingIsMarkedGray(thing)) - UnmarkGrayGCThingRecursively(thing, kind); + if (JS::IsIncrementalBarrierNeededOnTenuredGCThing(rt, thing, kind)) + JS::IncrementalReferenceBarrier(thing, kind); + else if (JS::GCThingIsMarkedGray(thing)) + JS::UnmarkGrayGCThingRecursively(thing, kind); } -static JS_ALWAYS_INLINE void -ExposeValueToActiveJS(const Value &v) +} /* namespace gc */ +} /* namespace js */ + +namespace JS { + +/* + * 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 +ExposeObjectToActiveJS(JSObject *obj) { - if (v.isMarkable()) - ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); + js::gc::ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); } -static JS_ALWAYS_INLINE void -ExposeObjectToActiveJS(JSObject *obj) +static MOZ_ALWAYS_INLINE void +ExposeScriptToActiveJS(JSScript *script) { - ExposeGCThingToActiveJS(obj, JSTRACE_OBJECT); + js::gc::ExposeGCThingToActiveJS(script, JSTRACE_SCRIPT); } /* * 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 +497,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)) + if (IsIncrementalBarrierNeededOnTenuredGCThing(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..b958c8e9cc 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/HashTable.h @@ -11,7 +11,6 @@ #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" @@ -73,7 +72,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 +158,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 +170,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 +181,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 +206,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 +313,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 +434,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 +478,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 +534,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 +545,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 +704,7 @@ class HashTableEntry } void destroy() { - JS_ASSERT(isLive()); + MOZ_ASSERT(isLive()); mem.addr()->~T(); } @@ -710,16 +713,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 +731,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 +761,64 @@ class HashTable : private AllocPolicy void nonNull() {} Entry *entry_; +#ifdef JS_DEBUG + const HashTable *table_; + uint32_t generation; +#endif protected: - Ptr(Entry &entry) : entry_(&entry) {} + Ptr(Entry &entry, const HashTable &tableArg) + : entry_(&entry) +#ifdef JS_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 { +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); +#endif + 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 { +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); +#endif + return !(*this == rhs); + } + + T &operator*() const { +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); +#endif + return entry_->get(); + } - T &operator*() const { return entry_->get(); } - T *operator->() const { return &entry_->get(); } + T *operator->() const { +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); +#endif + return &entry_->get(); + } }; // A Ptr that can be used to add a key after a failed lookup. @@ -782,9 +826,18 @@ class HashTable : private AllocPolicy { friend class HashTable; HashNumber keyHash; - mozilla::DebugOnly mutationCount; +#ifdef JS_DEBUG + uint64_t mutationCount; +#endif + + AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn) + : Ptr(entry, tableArg) + , keyHash(hn) +#ifdef JS_DEBUG + , mutationCount(tableArg.mutationCount) +#endif + {} - AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} public: // Leaves AddPtr uninitialized. AddPtr() {} @@ -799,32 +852,69 @@ 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 JS_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 JS_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 JS_DEBUG + , table_(nullptr) + , mutationCount(0) + , generation(0) + , validEntry(false) +#endif + {} bool empty() const { +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); +#endif return cur == end; } T &front() const { - JS_ASSERT(validEntry); - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); +#ifdef JS_DEBUG + MOZ_ASSERT(validEntry); + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); +#endif return cur->get(); } void popFront() { - JS_ASSERT(!empty()); + MOZ_ASSERT(!empty()); +#ifdef JS_DEBUG + MOZ_ASSERT(generation == table_->generation()); + MOZ_ASSERT(mutationCount == table_->mutationCount); +#endif while (++cur < end && !cur->isLive()) continue; +#ifdef JS_DEBUG validEntry = true; +#endif } }; @@ -837,17 +927,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 +947,26 @@ class HashTable : private AllocPolicy // if (e.front() == 42) // e.removeFront(); void removeFront() { - table.remove(*this->cur); + table_.remove(*this->cur); removed = true; +#ifdef JS_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); + JS_ASSERT(&k != &HashPolicy::getKey(this->cur->get())); + Ptr p(*this->cur, table_); + table_.rekeyWithoutRehash(p, l, k); rekeyed = true; +#ifdef JS_DEBUG this->validEntry = false; + this->mutationCount = table_.mutationCount; +#endif } void rekeyFront(const Key &k) { @@ -878,12 +976,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 +1006,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 - - void setTableSizeLog2(unsigned sizeLog2) - { - hashShift = sHashBits - sizeLog2; - } + static const size_t CAP_BITS = 24; -#ifdef DEBUG + 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 + uint64_t mutationCount; + mutable bool mEntered; mutable struct Stats { uint32_t searches; // total number of table searches @@ -939,16 +1037,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 +1055,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); @@ -982,7 +1081,7 @@ class HashTable : private AllocPolicy "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))); + return alloc.template pod_calloc(capacity); } static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32_t capacity) @@ -993,20 +1092,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 JS_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 +1217,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 +1246,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 +1277,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 +1297,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 +1378,7 @@ class HashTable : private AllocPolicy void remove(Entry &e) { - JS_ASSERT(table); + MOZ_ASSERT(table); METER(stats.removes++); if (e.hasCollision()) { @@ -1288,7 +1389,9 @@ class HashTable : private AllocPolicy e.clearLive(); } entryCount--; +#ifdef JS_DEBUG mutationCount++; +#endif } void checkUnderloaded() @@ -1371,13 +1474,16 @@ class HashTable : private AllocPolicy } removedCount = 0; entryCount = 0; +#ifdef JS_DEBUG mutationCount++; +#endif } void finish() { - JS_ASSERT(!entered); - +#ifdef JS_DEBUG + MOZ_ASSERT(!mEntered); +#endif if (!table) return; @@ -1386,36 +1492,38 @@ class HashTable : private AllocPolicy gen++; entryCount = 0; removedCount = 0; +#ifdef JS_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 +1541,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 +1555,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 +1563,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 +1584,11 @@ class HashTable : private AllocPolicy p.entry_->setLive(p.keyHash, mozilla::Forward(u)); entryCount++; +#ifdef JS_DEBUG mutationCount++; + p.generation = generation(); + p.mutationCount = mutationCount; +#endif return true; } @@ -1487,7 +1597,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 +1610,9 @@ class HashTable : private AllocPolicy entry->setLive(keyHash, mozilla::Forward(u)); entryCount++; +#ifdef JS_DEBUG mutationCount++; +#endif } // Note: |l| may be a reference to a piece of |u|, so this function @@ -1520,10 +1632,13 @@ class HashTable : private AllocPolicy template bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u) { +#ifdef JS_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 +1646,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 +1670,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..c7b71892ce 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); + js::gc::AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFunction *fun) +{ + js::gc::Cell *cell = reinterpret_cast(fun); + js::gc::AssertGCThingHasType(cell, JSTRACE_OBJECT); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSString *str) +{ + js::gc::Cell *cell = reinterpret_cast(str); + js::gc::AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSFlatString *flat) +{ + js::gc::Cell *cell = reinterpret_cast(flat); + js::gc::AssertGCThingHasType(cell, JSTRACE_STRING); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JS::Symbol *sym) +{ + js::gc::Cell *cell = reinterpret_cast(sym); + js::gc::AssertGCThingHasType(cell, JSTRACE_SYMBOL); + return cell; +} + +static MOZ_ALWAYS_INLINE js::gc::Cell * +AsCell(JSScript *script) +{ + js::gc::Cell *cell = reinterpret_cast(script); + js::gc::AssertGCThingHasType(cell, JSTRACE_SCRIPT); + return cell; +} + namespace shadow { struct ArenaHeader @@ -73,26 +169,26 @@ struct Zone JSTracer *const barrierTracer_; // A pointer to the JSRuntime's |gcMarker|. public: - bool needsBarrier_; + bool needsIncrementalBarrier_; Zone(JSRuntime *runtime, JSTracer *barrierTracerArg) : runtime_(runtime), barrierTracer_(barrierTracerArg), - needsBarrier_(false) + needsIncrementalBarrier_(false) {} - bool needsBarrier() const { - return needsBarrier_; + bool needsIncrementalBarrier() const { + return needsIncrementalBarrier_; } JSTracer *barrierTracer() { - JS_ASSERT(needsBarrier_); - JS_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_)); + MOZ_ASSERT(needsIncrementalBarrier_); + 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,30 +273,30 @@ IsInsideNursery(const JS::shadow::Runtime *runtime, const void *p) namespace JS { -static JS_ALWAYS_INLINE Zone * -GetGCThingZone(void *thing) +static MOZ_ALWAYS_INLINE Zone * +GetTenuredGCThingZone(void *thing) { - JS_ASSERT(thing); + MOZ_ASSERT(thing); +#ifdef JSGC_GENERATIONAL + JS_ASSERT(!js::gc::IsInsideNursery((js::gc::Cell *)thing)); +#endif return js::gc::GetGCThingArena(thing)->zone; } -static JS_ALWAYS_INLINE Zone * -GetObjectZone(JSObject *obj) -{ - return GetGCThingZone(obj); -} +extern JS_PUBLIC_API(Zone *) +GetObjectZone(JSObject *obj); -static JS_ALWAYS_INLINE bool +static MOZ_ALWAYS_INLINE bool GCThingIsMarkedGray(void *thing) { + MOZ_ASSERT(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. */ - 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,13 +304,17 @@ GCThingIsMarkedGray(void *thing) return *word & mask; } -static JS_ALWAYS_INLINE bool -IsIncrementalBarrierNeededOnGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) +static MOZ_ALWAYS_INLINE bool +IsIncrementalBarrierNeededOnTenuredGCThing(shadow::Runtime *rt, void *thing, JSGCTraceKind kind) { - if (!rt->needsBarrier_) + MOZ_ASSERT(thing); +#ifdef JSGC_GENERATIONAL + MOZ_ASSERT(!js::gc::IsInsideNursery((js::gc::Cell *)thing)); +#endif + if (!rt->needsIncrementalBarrier()) return false; - JS::Zone *zone = GetGCThingZone(thing); - return reinterpret_cast(zone)->needsBarrier_; + JS::Zone *zone = GetTenuredGCThingZone(thing); + return reinterpret_cast(zone)->needsIncrementalBarrier(); } } /* namespace JS */ 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..f2d89df5bd 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,165 @@ // 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 +/* + * 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); + +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); + 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 +188,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..1e246fcaa2 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,91 +111,86 @@ enum { IsLiveGCThing = true }; -struct ZoneStatsPod +} // namespace js + +namespace JS { + +struct ClassInfo { #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) + macro(Objects, IsLiveGCThing, objectsGCHeap) \ + macro(Objects, NotLiveGCThing, objectsMallocHeapSlots) \ + macro(Objects, NotLiveGCThing, objectsMallocHeapElementsNonAsmJS) \ + macro(Objects, NotLiveGCThing, objectsMallocHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, objectsNonHeapElementsAsmJS) \ + macro(Objects, NotLiveGCThing, objectsNonHeapElementsMapped) \ + macro(Objects, NotLiveGCThing, objectsNonHeapCodeAsmJS) \ + macro(Objects, NotLiveGCThing, objectsMallocHeapMisc) \ + \ + macro(Other, IsLiveGCThing, shapesGCHeapTree) \ + macro(Other, IsLiveGCThing, shapesGCHeapDict) \ + macro(Other, IsLiveGCThing, shapesGCHeapBase) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapDictTables) \ + macro(Other, NotLiveGCThing, shapesMallocHeapTreeKids) \ - ZoneStatsPod() + ClassInfo() : FOR_EACH_SIZE(ZERO_SIZE) - extra() + dummy() {} - void add(const ZoneStatsPod &other) { + void add(const ClassInfo &other) { FOR_EACH_SIZE(ADD_OTHER_SIZE) - // Do nothing with |extra|. + } + + void subtract(const ClassInfo &other) { + FOR_EACH_SIZE(SUB_OTHER_SIZE) + } + + 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) - // Do nothing with |extra|. return n; } - void addToTabSizes(JS::TabSizes *sizes) const { + void addToTabSizes(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. + int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) #undef FOR_EACH_SIZE }; -} // namespace js - -namespace JS { - -// Data for tracking memory usage of things hanging off objects. -struct ObjectsExtraSizes +// Holds data about a notable class (one whose combined object and shape +// instances use more than a certain amount of memory) so we can report it +// individually. +// +// The only difference between this class and ClassInfo is that this class +// holds a copy of the filename. +struct NotableClassInfo : public ClassInfo { -#define FOR_EACH_SIZE(macro) \ - macro(Objects, NotLiveGCThing, mallocHeapSlots) \ - macro(Objects, NotLiveGCThing, mallocHeapElementsNonAsmJS) \ - macro(Objects, NotLiveGCThing, mallocHeapElementsAsmJS) \ - macro(Objects, NotLiveGCThing, nonHeapElementsAsmJS) \ - 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) - } + NotableClassInfo(); + NotableClassInfo(const char *className, const ClassInfo &info); + NotableClassInfo(NotableClassInfo &&info); + NotableClassInfo &operator=(NotableClassInfo &&info); - size_t sizeOfLiveGCThings() const { - size_t n = 0; - FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - return n; + ~NotableClassInfo() { + js_free(className_); } - void addToTabSizes(TabSizes *sizes) const { - FOR_EACH_SIZE(ADD_TO_TAB_SIZES) - } + char *className_; - FOR_EACH_SIZE(DECL_SIZE) - int dummy; // present just to absorb the trailing comma from FOR_EACH_SIZE(ZERO_SIZE) - -#undef FOR_EACH_SIZE + private: + NotableClassInfo(const NotableClassInfo& info) MOZ_DELETE; }; // Data for tracking JIT-code memory usage. @@ -209,6 +214,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 +248,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--; + } + + 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) } - uint32_t numCopies:31; // How many copies of the string have we seen? - uint32_t isShort:1; // Is it a short string? + 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 +310,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 +317,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,151 +388,226 @@ 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 { #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, 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, compartmentTables) \ 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) - objectsExtra(), - extra() + classInfo(), + extra(), + allClasses(nullptr), + notableClasses(), + isTotals(true) {} - CompartmentStats(const CompartmentStats &other) + CompartmentStats(CompartmentStats &&other) : FOR_EACH_SIZE(COPY_OTHER_SIZE) - objectsExtra(other.objectsExtra), - extra(other.extra) - {} + classInfo(mozilla::Move(other.classInfo)), + extra(other.extra), + allClasses(other.allClasses), + notableClasses(mozilla::Move(other.notableClasses)), + isTotals(other.isTotals) + { + other.allClasses = nullptr; + MOZ_ASSERT(!other.isTotals); + } - void add(const CompartmentStats &other) { + ~CompartmentStats() { + // |allClasses| 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(allClasses); + } + + bool initClasses(JSRuntime *rt); + + void addSizes(const CompartmentStats &other) { + MOZ_ASSERT(isTotals); FOR_EACH_SIZE(ADD_OTHER_SIZE) - objectsExtra.add(other.objectsExtra); - // Do nothing with |extra|. + classInfo.add(other.classInfo); } size_t sizeOfLiveGCThings() const { + MOZ_ASSERT(isTotals); size_t n = 0; FOR_EACH_SIZE(ADD_SIZE_TO_N_IF_LIVE_GC_THING) - n += objectsExtra.sizeOfLiveGCThings(); - // Do nothing with |extra|. + n += classInfo.sizeOfLiveGCThings(); return n; } void addToTabSizes(TabSizes *sizes) const { + MOZ_ASSERT(isTotals); FOR_EACH_SIZE(ADD_TO_TAB_SIZES); - objectsExtra.addToTabSizes(sizes); - // Do nothing with |extra|. + classInfo.addToTabSizes(sizes); } + // The class measurements in |classInfo| are initially for all classes. At + // the end, if the measurement granularity is FineGrained, we subtract the + // measurements of the notable classes and move them into |notableClasses|. FOR_EACH_SIZE(DECL_SIZE) - ObjectsExtraSizes objectsExtra; - void *extra; // This field can be used by embedders. + ClassInfo classInfo; + void *extra; // This field can be used by embedders. + + typedef js::HashMap ClassesHashMap; + + // These are similar to |allStrings| and |notableStrings| in ZoneStats. + ClassesHashMap *allClasses; + js::Vector notableClasses; + bool isTotals; #undef FOR_EACH_SIZE }; @@ -454,7 +625,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 +688,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 +715,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..79fdd249a5 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,34 @@ */ #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; } - -namespace JS { - -struct FrameDescription -{ - JSScript *script; - unsigned lineno; - JSFunction *fun; -}; +struct JSFreeOp; -struct StackDescription -{ - unsigned nframes; - FrameDescription *frames; -}; +namespace js { +class InterpreterFrame; +class FrameIter; +class ScriptSource; +} -extern JS_PUBLIC_API(StackDescription *) -DescribeStack(JSContext *cx, unsigned maxFrames); -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) @@ -66,52 +53,8 @@ typedef enum JSTrapStatus { JSTRAP_LIMIT } JSTrapStatus; -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 @@ -155,43 +98,6 @@ JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, bool debug); JS_FRIEND_API(bool) JS_SetDebugMode(JSContext *cx, bool debug); -/* Turn on single step mode. */ -extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *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); - -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_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); - -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); /************************************************************************/ @@ -202,70 +108,14 @@ JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); 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, JSFunction *fun); - -extern JS_PUBLIC_API(JSNative) -JS_GetFunctionNative(JSContext *cx, JSFunction *fun); - -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptPrincipals(JSScript *script); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); -extern JS_PUBLIC_API(JSPrincipals *) -JS_GetScriptOriginPrincipals(JSScript *script); - -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 char *) -JS_GetScriptFilename(JSContext *cx, JSScript *script); +JS_GetScriptFilename(JSScript *script); extern JS_PUBLIC_API(const jschar *) JS_GetScriptSourceMap(JSContext *cx, JSScript *script); @@ -276,214 +126,9 @@ 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); - -/************************************************************************/ - -/* - * 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 */ - 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, JSObject *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_; - - protected: - JSAbstractFramePtr() - : ptr_(0) - { } - - public: - explicit JSAbstractFramePtr(void *raw); - - uintptr_t raw() const { return ptr_; } - - 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: - JSBrokenFrameIterator(JSContext *cx); - ~JSBrokenFrameIterator(); - - bool done() const; - JSBrokenFrameIterator& operator++(); - - JSAbstractFramePtr abstractFramePtr() const; - jsbytecode *pc() const; - - 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; - -/************************************************************************/ - -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 *) -JS_GetGlobalDebugHooks(JSRuntime *rt); - /** * Add various profiling-related functions as properties of the given object. */ @@ -492,27 +137,12 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpBytecode(JSContext *cx, JSScript *script); - -extern JS_PUBLIC_API(void) -JS_DumpCompartmentBytecode(JSContext *cx); - -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); -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/ios/js/Principals.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Principals.h new file mode 100644 index 0000000000..ad7a6262dd --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/Principals.h @@ -0,0 +1,98 @@ +/* -*- 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. */ + mozilla::Atomic refcount; + +#ifdef JS_DEBUG + /* A helper to facilitate principals debugging. */ + uint32_t debugToken; +#endif + + JSPrincipals() : refcount(0) {} + + 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/ProfilingFrameIterator.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingFrameIterator.h new file mode 100644 index 0000000000..0cb573402c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/ProfilingFrameIterator.h @@ -0,0 +1,81 @@ +/* -*- 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_ProfilingFrameIterator_h +#define js_ProfilingFrameIterator_h + +#include "mozilla/Alignment.h" + +#include + +#include "js/Utility.h" + +class JSAtom; +struct JSRuntime; + +namespace js { + class Activation; + class AsmJSProfilingFrameIterator; +} + +namespace JS { + +// This iterator can be used to walk the stack of a thread suspended at an +// arbitrary pc. To provide acurate results, profiling must have been enabled +// (via EnableRuntimeProfilingStack) before executing the callstack being +// unwound. +class JS_PUBLIC_API(ProfilingFrameIterator) +{ + js::Activation *activation_; + + static const unsigned StorageSpace = 6 * sizeof(void*); + mozilla::AlignedStorage storage_; + js::AsmJSProfilingFrameIterator &asmJSIter() { + JS_ASSERT(!done()); + return *reinterpret_cast(storage_.addr()); + } + const js::AsmJSProfilingFrameIterator &asmJSIter() const { + JS_ASSERT(!done()); + return *reinterpret_cast(storage_.addr()); + } + + void settle(); + + public: + struct RegisterState + { + RegisterState() : pc(nullptr), sp(nullptr), lr(nullptr) {} + void *pc; + void *sp; + void *lr; + }; + + ProfilingFrameIterator(JSRuntime *rt, const RegisterState &state); + ~ProfilingFrameIterator(); + void operator++(); + bool done() const { return !activation_; } + + // Assuming the stack grows down (we do), the return value: + // - always points into the stack + // - is weakly monotonically increasing (may be equal for successive frames) + // - will compare greater than newer native and psuedo-stack frame addresses + // and less than older native and psuedo-stack frame addresses + void *stackAddress() const; + + // Return a label suitable for regexp-matching as performed by + // browser/devtools/profiler/cleopatra/js/parserWorker.js + const char *label() const; + + private: + void iteratorConstruct(const RegisterState &state); + void iteratorConstruct(); + void iteratorDestroy(); + bool iteratorDone(); +}; + +} // namespace JS + +#endif /* js_ProfilingFrameIterator_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..99f2ef8760 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,124 @@ 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, + + // This ProfileEntry was pushed immediately before calling into asm.js. + ASMJS = 0x04, + + // Mask for removing all flags except the category information. + CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY & ~ASMJS + }; + + // Keep these in sync with browser/devtools/profiler/utils/global.js + MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t) + OTHER = 0x08, + CSS = 0x10, + JS = 0x20, + GC = 0x40, + CC = 0x80, + NETWORK = 0x100, + GRAPHICS = 0x200, + STORAGE = 0x400, + EVENTS = 0x800, + + 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 +162,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..792901685b 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/RootingAPI.h @@ -8,6 +8,7 @@ #define js_RootingAPI_h #include "mozilla/Attributes.h" +#include "mozilla/DebugOnly.h" #include "mozilla/GuardObjects.h" #include "mozilla/LinkedList.h" #include "mozilla/NullPtr.h" @@ -15,6 +16,8 @@ #include "jspubtd.h" +#include "js/GCAPI.h" +#include "js/HeapAPI.h" #include "js/TypeDecls.h" #include "js/Utility.h" @@ -101,8 +104,6 @@ namespace js { -class ScriptSourceObject; - template struct GCMethods {}; @@ -138,6 +139,8 @@ struct NullPtr namespace gc { struct Cell; +template +struct PersistentRootedMarker; } /* namespace gc */ } /* namespace js */ @@ -150,11 +153,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. * @@ -169,6 +167,23 @@ struct JS_PUBLIC_API(NullPtr) static void * const constNullValue; }; +#ifdef JSGC_GENERATIONAL +JS_FRIEND_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); +JS_FRIEND_API(void) HeapCellRelocate(js::gc::Cell **cellp); +#endif + +#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 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 @@ -198,6 +213,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 +251,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 +263,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 +285,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,21 +296,13 @@ class Heap : public js::HeapBase #endif } + enum { + crashOnTouchPointer = 1 + }; + T ptr; }; -#ifdef 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, @@ -315,31 +341,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 +385,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 +419,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 +489,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 +514,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; } @@ -548,11 +566,6 @@ class MOZ_STACK_CLASS MutableHandle : public js::MutableHandleBase void operator=(MutableHandle other) MOZ_DELETE; }; -#ifdef JSGC_GENERATIONAL -JS_PUBLIC_API(void) HeapCellPostBarrier(js::gc::Cell **cellp); -JS_PUBLIC_API(void) HeapCellRelocate(js::gc::Cell **cellp); -#endif - } /* namespace JS */ namespace js { @@ -612,7 +625,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 +634,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 +654,57 @@ 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 relocate(T **vp) {} +#endif +}; + +template <> +struct GCMethods +{ + static JSObject *initial() { return nullptr; } + static bool poisoned(JSObject *v) { return JS::IsPoisonedPtr(v); } + static gc::Cell *asGCThingOrNull(JSObject *v) { + if (!v) + return nullptr; + JS_ASSERT(uintptr_t(v) > 32); + return reinterpret_cast(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(T **vp) { + static void postBarrier(JSFunction **vp) { JS::HeapCellPostBarrier(reinterpret_cast(vp)); } - static void relocate(T **vp) { + static void relocate(JSFunction **vp) { JS::HeapCellRelocate(reinterpret_cast(vp)); } #endif }; -#if defined(DEBUG) +#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 +729,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 +755,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 +777,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 +793,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 +814,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 +835,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 +846,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 +855,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 +874,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 +925,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 +952,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 +984,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 +1023,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 +1078,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 +1111,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 +1123,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 +1133,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 +1143,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 +1170,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 +1181,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,37 +1192,68 @@ class PersistentRooted : public mozilla::LinkedListElement > T ptr; }; -} /* namespace JS */ +class JS_PUBLIC_API(ObjectPtr) +{ + Heap value; -namespace js { + public: + ObjectPtr() : value(nullptr) {} -/* - * 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 -} + explicit ObjectPtr(JSObject *obj) : value(obj) {} -/* Base class for automatic read-only object rooting during compilation. */ -class CompilerRootNode -{ - protected: - CompilerRootNode(js::gc::Cell *ptr) : next(nullptr), ptr_(ptr) {} + /* Always call finalize before the destructor. */ + ~ObjectPtr() { MOZ_ASSERT(!value); } - public: - void **address() { return (void **)&ptr_; } + void finalize(JSRuntime *rt) { + if (IsIncrementalBarrierNeeded(rt)) + IncrementalObjectBarrier(value); + value = nullptr; + } - public: - CompilerRootNode *next; + void init(JSObject *obj) { value = obj; } + + JSObject *get() const { return value; } + + void writeBarrierPre(JSRuntime *rt) { + IncrementalObjectBarrier(value); + } + + bool isAboutToBeFinalized(); - protected: - js::gc::Cell *ptr_; + 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 */ + +namespace js { +namespace gc { + +template +void +CallTraceCallbackOnNonHeap(T *v, const TraceCallbacks &aCallbacks, const char *aName, void *aClosure) +{ + static_assert(sizeof(T) == sizeof(JS::Heap), "T and Heap must be compatible."); + MOZ_ASSERT(v); + mozilla::DebugOnly cell = GCMethods::asGCThingOrNull(*v); + MOZ_ASSERT(cell); + MOZ_ASSERT(!IsInsideNursery(cell)); + JS::Heap *asHeapT = reinterpret_cast*>(v); + aCallbacks.Trace(asHeapT, aName, aClosure); + MOZ_ASSERT(GCMethods::asGCThingOrNull(*v) == cell); +} + +} /* namespace gc */ + +} /* namespace js */ #endif /* js_RootingAPI_h */ 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/TracingAPI.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TracingAPI.h new file mode 100644 index 0000000000..fef0e5dec7 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TracingAPI.h @@ -0,0 +1,219 @@ +/* -*- 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::Heap *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallIdTracer(JSTracer *trc, JS::Heap *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallObjectTracer(JSTracer *trc, JS::Heap *objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallStringTracer(JSTracer *trc, JS::Heap *strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallScriptTracer(JSTracer *trc, JS::Heap *scriptp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallFunctionTracer(JSTracer *trc, JS::Heap *funp, const char *name); + +// The following JS_CallUnbarriered*Tracer functions should only be called where +// you know for sure that a heap post barrier is not required. Use with extreme +// caution! +extern JS_PUBLIC_API(void) +JS_CallUnbarrieredValueTracer(JSTracer *trc, JS::Value *valuep, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallUnbarrieredIdTracer(JSTracer *trc, jsid *idp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallUnbarrieredObjectTracer(JSTracer *trc, JSObject **objp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallUnbarrieredStringTracer(JSTracer *trc, JSString **strp, const char *name); + +extern JS_PUBLIC_API(void) +JS_CallUnbarrieredScriptTracer(JSTracer *trc, JSScript **scriptp, 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_CallUnbarrieredObjectTracer(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/ios/js/TypeDecls.h b/frameworks/js-bindings/external/spidermonkey/include/ios/js/TypeDecls.h index 027d7b8fb7..1d275006eb 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..6c369938b0 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNode.h @@ -0,0 +1,503 @@ +/* -*- 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, object, or symbol; +// - 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; + + explicit 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. + // + // If wantNames is true, compute names for edges. Doing so can be expensive + // in time and memory. + virtual EdgeRange *edges(JSContext *cx, bool wantNames) const = 0; + + // Return the Zone to which this node's referent belongs, or nullptr if the + // referent is not of a type allocated in SpiderMonkey Zones. + virtual JS::Zone *zone() const = 0; + + // Return the compartment for this node. Some ubi::Node referents are not + // associated with JSCompartments, such as JSStrings (which are associated + // with Zones). When the referent is not associated with a compartment, + // nullptr is returned. + virtual JSCompartment *compartment() 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. + explicit 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, JS::Symbols, 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(); } + JS::Zone *zone() const { return base()->zone(); } + JSCompartment *compartment() const { return base()->compartment(); } + EdgeRange *edges(JSContext *cx, bool wantNames = true) const { + return base()->edges(cx, wantNames); + } + + // 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. This may be nullptr, if Node::edges was called with + // false as the wantNames parameter. + // + // 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 *, bool wantNames) const MOZ_OVERRIDE; + JS::Zone *zone() const MOZ_OVERRIDE { return get().zone(); } + JSCompartment *compartment() const MOZ_OVERRIDE { return nullptr; } + + protected: + explicit TracerConcrete(Referent *ptr) : Base(ptr) { } + Referent &get() const { return *static_cast(ptr); } + + public: + static const jschar concreteTypeName[]; + static void construct(void *storage, Referent *ptr) { new (storage) TracerConcrete(ptr); } +}; + +// For JS_TraceChildren-based types that have a 'compartment' method. +template +class TracerConcreteWithCompartment : public TracerConcrete { + typedef TracerConcrete TracerBase; + JSCompartment *compartment() const MOZ_OVERRIDE { + return TracerBase::get().compartment(); + } + + TracerConcreteWithCompartment(Referent *ptr) : TracerBase(ptr) { } + + public: + static void construct(void *storage, Referent *ptr) { + new (storage) TracerConcreteWithCompartment(ptr); + } +}; + +template<> struct Concrete : TracerConcreteWithCompartment { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcreteWithCompartment { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcrete { }; +template<> struct Concrete : TracerConcreteWithCompartment { }; +template<> struct Concrete : TracerConcreteWithCompartment { }; +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, bool wantNames) const MOZ_OVERRIDE; + JS::Zone *zone() const MOZ_OVERRIDE; + JSCompartment *compartment() const MOZ_OVERRIDE; + + explicit 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..d64e027269 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/js/UbiNodeTraverse.h @@ -0,0 +1,234 @@ +/* -*- 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.abandonReferent()| if it +// doesn't want to traverse the outgoing edges of |edge.referent|. You can +// use this to limit the traversal to a given portion of the graph: it will +// never visit nodes reachable only through nodes that you have abandoned. +// Note that |abandonReferent| must be called the first time the given node +// is reached; that is, |first| must be true. +// +// The visitor function may call |traversal.stop()| if it doesn't want +// to visit any more nodes at all. +// +// 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) + : wantNames(true), cx(cx), visited(cx), handler(handler), pending(cx), + traversalBegun(false), stopRequested(false), abandonRequested(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); } + + // True if the handler wants us to compute edge names; doing so can be + // expensive in time and memory. True by default. + bool wantNames; + + // 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, wantNames)); + 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|. + // Mark it as visited. + if (!visited.add(a, edge.referent, typename Handler::NodeData())) + 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; + + // Arrange to traverse this edge's referent's outgoing edges + // later --- unless |handler| asked us not to. + if (abandonRequested) { + // Skip the enqueue; reset flag for future iterations. + abandonRequested = false; + } else if (first) { + if (!pending.append(edge.referent)) + return false; + } + } + } + + 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; } + + // Request that the current edge's referent's outgoing edges not be + // traversed. This must be called the first time that referent is reached. + // Other edges *to* that referent will still be traversed. + void abandonReferent() { abandonRequested = 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: + explicit 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; + + // True if we've been asked to abandon the current edge's referent. + bool abandonRequested; +}; + +} // 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..ed4f09fa35 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,23 @@ 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_MOVED_TENURED_PATTERN 0x49 +#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 +59,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 +124,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 +171,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 +328,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 +522,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 +533,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 +556,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) @@ -444,6 +564,16 @@ js_pod_calloc(size_t numElems) return (T *)js_calloc(numElems * sizeof(T)); } +template +static MOZ_ALWAYS_INLINE T * +js_pod_realloc(T *prior, size_t oldSize, size_t newSize) +{ + MOZ_ASSERT(!(oldSize & mozilla::tl::MulOverflowMask::value)); + if (newSize & mozilla::tl::MulOverflowMask::value) + return nullptr; + return (T *)js_realloc(prior, newSize * sizeof(T)); +} + namespace js { template @@ -471,6 +601,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 +684,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 +693,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..d8ec20f38f 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() { @@ -1244,15 +1340,22 @@ class Value }; inline bool -IsPoisonedValue(const Value &v) +IsOptimizedPlaceholderMagicValue(const Value &v) { - if (v.isString()) - return IsPoisonedPtr(v.toString()); - if (v.isObject()) - return IsPoisonedPtr(&v.toObject()); + 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()) + js::gc::ExposeGCThingToActiveJS(v.toGCThing(), v.gcKind()); +} + /************************************************************************/ static inline Value @@ -1315,6 +1418,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 +1474,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 +1626,23 @@ 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); } + static bool poisoned(const JS::Value &v) { + return v.isMarkable() && JS::IsPoisonedPtr(v.toGCThing()); + } }; 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 poisoned(const JS::Value &v) { + return v.isMarkable() && JS::IsPoisonedPtr(v.toGCThing()); + } + static gc::Cell *asGCThingOrNull(const JS::Value &v) { + return v.isMarkable() ? v.toGCThing() : nullptr; + } + 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 +1674,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 +1690,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(); } + gc::Cell *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 +1725,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 +1756,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 +1771,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; } @@ -1727,6 +1859,12 @@ IMPL_TO_JSVAL(jsval_layout l) namespace JS { +inline bool +IsPoisonedValue(const Value &v) +{ + return js::GCMethods::poisoned(v); +} + #ifndef __GNUC__ /* * The default assignment operator for |struct C| has the signature: @@ -1747,7 +1885,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1759,7 +1897,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1775,52 +1913,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) { @@ -1847,28 +1945,9 @@ DOUBLE_TO_JSVAL(double d) 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 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)); + return i <= JSVAL_INT_MAX + ? INT_TO_JSVAL((int32_t)i) + : DOUBLE_TO_JSVAL((double)i); } static inline jsval @@ -1877,13 +1956,6 @@ 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 +1964,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 +1978,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 +1991,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..887cfa4d59 --- /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..82a90f8c4d 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,15 +19,17 @@ namespace js { -class ContextFriendFields; +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); } + template T *pod_malloc(size_t numElems) { return js_pod_malloc(numElems); } + template T *pod_calloc(size_t numElems) { return js_pod_calloc(numElems); } + template T *pod_realloc(T *p, size_t oldSize, size_t newSize) { + return js_pod_realloc(p, oldSize, newSize); + } void free_(void *p) { js_free(p); } void reportAllocOverflow() const {} }; @@ -47,27 +54,30 @@ class TempAllocPolicy JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes); public: - TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( - TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} - - void *malloc_(size_t bytes) { - void *p = js_malloc(bytes); - if (JS_UNLIKELY(!p)) - p = onOutOfMemory(nullptr, bytes); + MOZ_IMPLICIT TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :( + MOZ_IMPLICIT TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {} + + template + T *pod_malloc(size_t numElems) { + T *p = js_pod_malloc(numElems); + if (MOZ_UNLIKELY(!p)) + p = static_cast(onOutOfMemory(nullptr, numElems * sizeof(T))); return p; } - void *calloc_(size_t bytes) { - void *p = js_calloc(bytes); - if (JS_UNLIKELY(!p)) - p = onOutOfMemory(nullptr, bytes); + template + T *pod_calloc(size_t numElems) { + T *p = js_pod_calloc(numElems); + if (MOZ_UNLIKELY(!p)) + p = static_cast(onOutOfMemory(reinterpret_cast(1), numElems * sizeof(T))); return p; } - void *realloc_(void *p, size_t oldBytes, size_t bytes) { - void *p2 = js_realloc(p, bytes); - if (JS_UNLIKELY(!p2)) - p2 = onOutOfMemory(p2, bytes); + template + T *pod_realloc(T *prior, size_t oldSize, size_t newSize) { + T *p2 = js_pod_realloc(prior, oldSize, newSize); + if (MOZ_UNLIKELY(!p2)) + p2 = static_cast(onOutOfMemory(p2, newSize * sizeof(T))); 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..0f1b2d1cba 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 +#ifdef 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_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); /* * 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, - 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); +(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, + JS::HandleObject objectPassedToWrap); 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); } @@ -873,58 +803,103 @@ JS_NumberValue(double 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); - -/* - * 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 */ /************************************************************************/ -/* Property attributes, set in JSPropertySpec and passed to API functions. */ +/* Property attributes, set in JSPropertySpec and passed to API functions. + * + * NB: The data structure in which some of these values are stored only uses + * a uint8_t to store the relevant information. Proceed with caution if + * trying to reorder or change the the first byte worth of flags. + */ #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 @@ -941,8 +916,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 @@ -950,6 +923,18 @@ class AutoIdRooter : private AutoGCRooter #define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */ +#define JSPROP_IGNORE_ENUMERATE 0x1000 /* ignore the value in JSPROP_ENUMERATE. + This flag only valid when defining over + an existing property. */ +#define JSPROP_IGNORE_READONLY 0x2000 /* ignore the value in JSPROP_READONLY. + This flag only valid when defining over + an existing property. */ +#define JSPROP_IGNORE_PERMANENT 0x4000 /* ignore the value in JSPROP_PERMANENT. + This flag only valid when defining over + an existing property. */ +#define JSPROP_IGNORE_VALUE 0x8000 /* ignore the Value in the descriptor. Nothing was + specified when passed to Object.defineProperty + from script. */ /* * Specify a generic native prototype methods, i.e., methods of a class @@ -1029,13 +1014,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 +1035,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 +1060,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 +1072,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 +1085,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 +1115,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 +1148,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 +1160,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 +1172,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,16 +1201,13 @@ ToUint64(JSContext *cx, JS::Handle v, uint64_t *out) } /* namespace JS */ extern JS_PUBLIC_API(JSType) -JS_TypeOfValue(JSContext *cx, jsval v); - -extern JS_PUBLIC_API(const char *) -JS_GetTypeName(JSContext *cx, JSType type); +JS_TypeOfValue(JSContext *cx, JS::Handle v); 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 +1230,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 +1267,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 +1292,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 +1320,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; @@ -1366,18 +1337,18 @@ class JSAutoRequest #if 0 private: - static void *operator new(size_t) CPP_THROW_NEW { return 0; }; - static void operator delete(void *, size_t) { }; + static void *operator new(size_t) CPP_THROW_NEW { return 0; } + static void operator delete(void *, size_t) { } #endif }; 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 +#ifdef JS_DEBUG mContext = cx; JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx))); #endif @@ -1385,14 +1356,14 @@ class JSAutoCheckRequest } ~JSAutoCheckRequest() { -#if defined JS_THREADSAFE && defined DEBUG +#ifdef JS_DEBUG JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext))); #endif } private: -#if defined JS_THREADSAFE && defined DEBUG +#ifdef JS_DEBUG JSContext *mContext; #endif MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -1448,157 +1419,144 @@ 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) + extraWarnings_(false), + varObjFix_(false) { } - bool extraWarnings() const { return extraWarnings_; } - ContextOptions &setExtraWarnings(bool flag) { - extraWarnings_ = flag; - return *this; - } - ContextOptions &toggleExtraWarnings() { - extraWarnings_ = !extraWarnings_; - return *this; - } - - bool werror() const { return werror_; } - ContextOptions &setWerror(bool flag) { - werror_ = flag; - return *this; - } - ContextOptions &toggleWerror() { - werror_ = !werror_; - return *this; - } - - bool varObjFix() const { return varObjFix_; } - ContextOptions &setVarObjFix(bool flag) { - varObjFix_ = flag; + bool baseline() const { return baseline_; } + RuntimeOptions &setBaseline(bool flag) { + baseline_ = flag; return *this; } - ContextOptions &toggleVarObjFix() { - varObjFix_ = !varObjFix_; + RuntimeOptions &toggleBaseline() { + baseline_ = !baseline_; return *this; } - bool privateIsNSISupports() const { return privateIsNSISupports_; } - ContextOptions &setPrivateIsNSISupports(bool flag) { - privateIsNSISupports_ = flag; + bool ion() const { return ion_; } + RuntimeOptions &setIon(bool flag) { + ion_ = flag; return *this; } - ContextOptions &togglePrivateIsNSISupports() { - privateIsNSISupports_ = !privateIsNSISupports_; + RuntimeOptions &toggleIon() { + ion_ = !ion_; return *this; } - bool dontReportUncaught() const { return dontReportUncaught_; } - ContextOptions &setDontReportUncaught(bool flag) { - dontReportUncaught_ = flag; + bool asmJS() const { return asmJS_; } + RuntimeOptions &setAsmJS(bool flag) { + asmJS_ = flag; return *this; } - ContextOptions &toggleDontReportUncaught() { - dontReportUncaught_ = !dontReportUncaught_; + RuntimeOptions &toggleAsmJS() { + asmJS_ = !asmJS_; return *this; } - bool noDefaultCompartmentObject() const { return noDefaultCompartmentObject_; } - ContextOptions &setNoDefaultCompartmentObject(bool flag) { - noDefaultCompartmentObject_ = flag; - return *this; - } - ContextOptions &toggleNoDefaultCompartmentObject() { - noDefaultCompartmentObject_ = !noDefaultCompartmentObject_; + bool nativeRegExp() const { return nativeRegExp_; } + RuntimeOptions &setNativeRegExp(bool flag) { + nativeRegExp_ = flag; return *this; } - bool noScriptRval() const { return noScriptRval_; } - ContextOptions &setNoScriptRval(bool flag) { - noScriptRval_ = flag; + bool werror() const { return werror_; } + RuntimeOptions &setWerror(bool flag) { + werror_ = flag; return *this; } - ContextOptions &toggleNoScriptRval() { - noScriptRval_ = !noScriptRval_; + RuntimeOptions &toggleWerror() { + werror_ = !werror_; return *this; } bool strictMode() const { return strictMode_; } - ContextOptions &setStrictMode(bool flag) { + RuntimeOptions &setStrictMode(bool flag) { strictMode_ = flag; return *this; } - ContextOptions &toggleStrictMode() { + RuntimeOptions &toggleStrictMode() { strictMode_ = !strictMode_; return *this; } - bool baseline() const { return baseline_; } - ContextOptions &setBaseline(bool flag) { - baseline_ = flag; + bool extraWarnings() const { return extraWarnings_; } + RuntimeOptions &setExtraWarnings(bool flag) { + extraWarnings_ = flag; return *this; } - ContextOptions &toggleBaseline() { - baseline_ = !baseline_; + RuntimeOptions &toggleExtraWarnings() { + extraWarnings_ = !extraWarnings_; return *this; } - bool typeInference() const { return typeInference_; } - ContextOptions &setTypeInference(bool flag) { - typeInference_ = flag; + bool varObjFix() const { return varObjFix_; } + RuntimeOptions &setVarObjFix(bool flag) { + varObjFix_ = flag; return *this; } - ContextOptions &toggleTypeInference() { - typeInference_ = !typeInference_; + RuntimeOptions &toggleVarObjFix() { + varObjFix_ = !varObjFix_; return *this; } - bool ion() const { return ion_; } - ContextOptions &setIon(bool flag) { - ion_ = flag; + private: + bool baseline_ : 1; + bool ion_ : 1; + bool asmJS_ : 1; + bool nativeRegExp_ : 1; + bool werror_ : 1; + bool strictMode_ : 1; + bool extraWarnings_ : 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() + : privateIsNSISupports_(false), + dontReportUncaught_(false) + { + } + + bool privateIsNSISupports() const { return privateIsNSISupports_; } + ContextOptions &setPrivateIsNSISupports(bool flag) { + privateIsNSISupports_ = flag; return *this; } - ContextOptions &toggleIon() { - ion_ = !ion_; + ContextOptions &togglePrivateIsNSISupports() { + privateIsNSISupports_ = !privateIsNSISupports_; return *this; } - bool asmJS() const { return asmJS_; } - ContextOptions &setAsmJS(bool flag) { - asmJS_ = flag; + bool dontReportUncaught() const { return dontReportUncaught_; } + ContextOptions &setDontReportUncaught(bool flag) { + dontReportUncaught_ = flag; return *this; } - ContextOptions &toggleAsmJS() { - asmJS_ = !asmJS_; + ContextOptions &toggleDontReportUncaught() { + dontReportUncaught_ = !dontReportUncaught_; 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 +1564,7 @@ ContextOptionsRef(JSContext *cx); class JS_PUBLIC_API(AutoSaveContextOptions) { public: - AutoSaveContextOptions(JSContext *cx) + explicit AutoSaveContextOptions(JSContext *cx) : cx_(cx), oldOptions_(ContextOptionsRef(cx_)) { @@ -1624,9 +1582,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 +1618,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,11 +1669,20 @@ class JS_PUBLIC_API(JSAutoCompartment) ~JSAutoCompartment(); }; -/* 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) +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); @@ -1743,7 +1704,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 +1720,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) -JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj); +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); @@ -1782,21 +1763,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 +1806,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 +1818,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 @@ -1887,7 +1863,7 @@ 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); +JS_realloc(JSContext *cx, void *p, size_t oldBytes, size_t newBytes); /* * A wrapper for js_free(p) that may delay js_free(p) invocation as a @@ -1917,6 +1893,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 +1921,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 +1984,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 +2019,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 +2125,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 +2149,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 +2200,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 +2220,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 +2255,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 +2270,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 +2331,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 +2340,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 +2371,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 +2383,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 +2399,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 +2458,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 +2468,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 +2487,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 { @@ -2559,11 +2523,11 @@ class JS_PUBLIC_API(CompartmentOptions) if (mode_ == Default) return defaultValue; return mode_ == ForceTrue; - }; + } void set(bool overrideValue) { mode_ = overrideValue ? ForceTrue : ForceFalse; - }; + } void reset() { mode_ = Default; @@ -2582,6 +2546,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 +2567,40 @@ 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; + } + + // 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 typeInference(const js::ExclusiveContext *cx) const; - Override &typeInferenceOverride() { return typeInferenceOverride_; } - bool ion(JSContext *cx) const; - Override &ionOverride() { return ionOverride_; } + bool cloneSingletons() const { return cloneSingletons_; } + CompartmentOptions &setCloneSingletons(bool flag) { + cloneSingletons_ = flag; + return *this; + } - bool asmJS(JSContext *cx) const; - Override &asmJSOverride() { return asmJSOverride_; } + bool extraWarnings(JSRuntime *rt) const; + bool extraWarnings(JSContext *cx) const; + Override &extraWarningsOverride() { return extraWarningsOverride_; } void *zonePointer() const { JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone)); @@ -2623,22 +2610,56 @@ 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_; + Override extraWarningsOverride_; 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 +2694,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 +2728,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 +2737,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_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_HasProperty(JSContext *cx, JSObject *obj, const char *name, bool *foundp); +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_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, bool *foundp); +JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + bool *foundp); extern JS_PUBLIC_API(bool) -JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, JS::MutableHandle vp); +JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); extern JS_PUBLIC_API(bool) -JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, - unsigned flags, JS::MutableHandle vp); +JS_LookupProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, - unsigned flags, JSObject **objp, JS::MutableHandle vp); +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 +2874,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 +2910,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 +2960,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 +3008,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 +3032,186 @@ 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_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); +JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, + JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, - JS::MutableHandle vp); +JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, JS::Handle v); +JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); extern JS_PUBLIC_API(bool) -JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, JS::Handle v); +JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); extern JS_PUBLIC_API(bool) -JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +JS_DeleteProperty2(JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); extern JS_PUBLIC_API(bool) -JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded); +JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); extern JS_PUBLIC_API(bool) -JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); 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::HandleValue 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, + JS::HandleObject 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, + JS::HandleString 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, + 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, 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); -/* - * 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_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_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle vp); +JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); extern JS_PUBLIC_API(bool) -JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index); +JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); extern JS_PUBLIC_API(bool) -JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded); +JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); -/* - * 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); +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); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3077,48 +3221,49 @@ 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. It must be legal to pass + * these contents to free(). 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. + * Create a new mapped array buffer with the given memory mapped contents. It + * must be legal to free the contents pointer by unmapping it. On success, + * ownership is transferred to the new mapped array buffer. */ -extern JS_PUBLIC_API(bool) -JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +extern JS_PUBLIC_API(JSObject *) +JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents); /* - * 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. + * Create memory mapped array buffer contents. + * Caller must take care of closing fd after calling this function. */ -extern JS_PUBLIC_API(bool) -JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents, uint8_t **data); +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 +3271,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 +3279,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 +3289,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 +3302,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 +3365,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 +3388,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 +3398,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 +3488,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 +3503,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 +3514,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) column(0), compileAndGo(false), forEval(false), + defineOnScope(true), noScriptRval(false), selfHostingMode(false), canLazilyParse(true), @@ -3433,7 +3523,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 +3538,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 +3554,7 @@ class JS_PUBLIC_API(ReadOnlyCompileOptions) unsigned column; bool compileAndGo; bool forEval; + bool defineOnScope; bool noScriptRval; bool selfHostingMode; bool canLazilyParse; @@ -3466,11 +3563,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 +3591,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 +3607,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 +3648,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 +3678,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 +3732,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 +3788,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 +3797,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 jschar *chars, size_t length); + 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, 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 +3831,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 +3870,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_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, - JSPrincipals *principals, - const char *bytes, unsigned length, - const char *filename, unsigned lineno, - jsval *rval); +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_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 +4047,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 +4122,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 +4140,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 +4273,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 +4305,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 +4330,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 +4365,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 +4462,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 +4499,6 @@ struct JSLocaleCallbacks { JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; - JSErrorCallback localeGetErrorMessage; }; /* @@ -4357,8 +4636,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 +4693,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 +4706,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 +4756,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 +4822,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 +4864,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 +4879,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 +4903,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 +4927,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 +5013,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 +5034,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 +5044,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 +5081,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..b2ffe0b86f 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" @@ -16,52 +20,45 @@ #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. - */ #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(limit, sp) ((uintptr_t)(sp) < (limit)) #else -# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \ - ((uintptr_t)(sp) > (limit)-(tolerance)) +# define JS_CHECK_STACK_SIZE(limit, sp) ((uintptr_t)(sp) > (limit)) #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; -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 +70,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. @@ -107,7 +104,8 @@ enum { 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 + JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS, + JS_TELEMETRY_DEPRECATED_LANGUAGE_EXTENSIONS_IN_CONTENT }; typedef void @@ -122,16 +120,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 +154,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 +193,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 +230,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 +402,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 +453,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 +489,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 +532,7 @@ struct TypeObject { }; struct BaseShape { - const js::Class *clasp; + const js::Class *clasp_; JSObject *parent; JSObject *_1; JSCompartment *compartment; @@ -427,10 +580,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 +614,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 +680,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,29 +692,24 @@ 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 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); -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 +719,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 +734,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 +741,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 +796,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) +{ + 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) { - using shadow::Atom; - return reinterpret_cast(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT; + 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; } -inline JSLinearString * +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,53 +950,65 @@ 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); inline uintptr_t -GetNativeStackLimit(JSContext *cx) +GetNativeStackLimit(JSContext *cx, StackKind kind, int extraAllowance = 0) { - StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript - : StackForUntrustedScript; PerThreadDataFriendFields *mainThread = PerThreadDataFriendFields::getMainThread(GetRuntime(cx)); - return mainThread->nativeStackLimit[kind]; + uintptr_t limit = mainThread->nativeStackLimit[kind]; +#if JS_STACK_GROWTH_DIRECTION > 0 + limit += extraAllowance; +#else + limit -= extraAllowance; +#endif + return limit; +} + +inline uintptr_t +GetNativeStackLimit(JSContext *cx, int extraAllowance = 0) +{ + StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript + : StackForUntrustedScript; + return GetNativeStackLimit(cx, kind, extraAllowance); } /* * 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. + * 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 allows less space than any other check, + * including a safety buffer (as in, it uses the untrusted limit and subtracts + * a little more from it). */ -#define JS_CHECK_RECURSION(cx, onerror) \ +#define JS_CHECK_RECURSION_LIMIT(cx, limit, onerror) \ JS_BEGIN_MACRO \ int stackDummy_; \ - if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \ + if (!JS_CHECK_STACK_SIZE(limit, &stackDummy_)) { \ js_ReportOverRecursed(cx); \ onerror; \ } \ JS_END_MACRO +#define JS_CHECK_RECURSION(cx, onerror) \ + JS_CHECK_RECURSION_LIMIT(cx, js::GetNativeStackLimit(cx), onerror) + #define JS_CHECK_RECURSION_DONT_REPORT(cx, onerror) \ JS_BEGIN_MACRO \ int stackDummy_; \ @@ -711,17 +1032,11 @@ GetNativeStackLimit(JSContext *cx) } \ 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_SYSTEM_RECURSION(cx, onerror) \ + JS_CHECK_RECURSION_LIMIT(cx, js::GetNativeStackLimit(cx, js::StackForSystemCode), onerror) + +#define JS_CHECK_RECURSION_CONSERVATIVE(cx, onerror) \ + JS_CHECK_RECURSION_LIMIT(cx, js::GetNativeStackLimit(cx, js::StackForUntrustedScript, -1024 * int(sizeof(size_t))), onerror) JS_FRIEND_API(void) StartPCCountProfiling(JSContext *cx); @@ -741,10 +1056,8 @@ 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); @@ -764,9 +1077,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 +1110,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 +1150,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; } @@ -933,57 +1247,206 @@ js_DateGetMsecSinceEpoch(JSObject *obj); * string and its arguments. */ typedef enum JSErrNum { -#define MSG_DEF(name, number, count, exception, format) \ - name = number, +#define MSG_DEF(name, count, exception, format) \ + name, #include "js.msg" #undef MSG_DEF JSErr_Limit } 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: + explicit 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) +{ + explicit 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, - - /* - * Type returned for a DataView. Note that there is no single element type - * in this case. - */ - TYPE_DATAVIEW, + Uint8Clamped, - 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 +1482,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 +1507,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 +1582,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::AssertedCast(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 +1698,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 +1727,23 @@ 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. + * Return true if the arrayBuffer contains any data. This will return false for + * ArrayBuffer.prototype and neutered ArrayBuffers. * * |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(uint8_t *) -JS_GetArrayBufferData(JSObject *obj); +extern JS_FRIEND_API(bool) +JS_ArrayBufferHasData(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. @@ -1236,13 +1793,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 +1823,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 +1843,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 +1948,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 +2010,12 @@ class JSJitMethodCallArgs : protected JS::detail::CallArgsBaseusedRval_, which we don't have. + return argv_[-2].toObject(); + } + // Add get() as needed }; @@ -1451,7 +2045,10 @@ struct JSJitInfo { Getter, Setter, Method, - OpType_None + ParallelNative, + StaticMethod, + // Must be last + OpTypeCount }; enum ArgType { @@ -1475,6 +2072,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 +2094,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 isTypedMethod; + } + + OpType type() const + { + return OpType(type_); + } + + AliasSet aliasSet() const { - return type != OpType_None; + 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.)."); + +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); -static JS_ALWAYS_INLINE const JSJitInfo * +} // 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 +2269,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 +2282,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 +2317,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 +2327,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 +2349,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 +2376,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 +2430,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 +2450,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 +2476,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 +2521,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..75178049f1 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,62 @@ #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)) \ + real(WeakSet, 42, js_InitWeakSetClass, OCLASP(WeakSet)) \ #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..8f3a9b1b9f 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: @@ -71,38 +87,67 @@ class JS_FRIEND_API(Wrapper); */ class JS_FRIEND_API(BaseProxyHandler) { + /* + * Sometimes it's desirable to designate groups of proxy handlers as "similar". + * For this, we use the notion of a "family": A consumer-provided opaque pointer + * that designates the larger group to which this proxy belongs. + * + * If it will never be important to differentiate this proxy from others as + * part of a distinct group, nullptr may be used instead. + */ 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; } - public: - explicit BaseProxyHandler(const void *family); - virtual ~BaseProxyHandler(); + /* + * 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; - bool hasPrototype() { + public: + explicit MOZ_CONSTEXPR BaseProxyHandler(const void *aFamily, bool aHasPrototype = false, + bool aHasSecurityPolicy = false) + : mFamily(aFamily), + mHasPrototype(aHasPrototype), + mHasSecurityPolicy(aHasSecurityPolicy) + { } + + 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 +164,77 @@ 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 calls to ::get() + * ::set(), in addition to being invoked on its own, so there are several + * valid Actions that could have been entered. */ - enum Action { - GET, - SET, - CALL + typedef uint32_t Action; + enum { + NONE = 0x00, + GET = 0x01, + SET = 0x02, + CALL = 0x04, + ENUMERATE = 0x08, + GET_PROPERTY_DESCRIPTOR = 0x10 }; + 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 boxedValue_unbox(JSContext *cx, HandleObject proxy, MutableHandleValue vp) 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 +250,61 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(const void *family); + explicit MOZ_CONSTEXPR DirectProxyHandler(const void *aFamily, bool aHasPrototype = false, + bool aHasSecurityPolicy = false) + : BaseProxyHandler(aFamily, aHasPrototype, aHasSecurityPolicy) + { } /* 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 bool boxedValue_unbox(JSContext *cx, HandleObject proxy, MutableHandleValue vp) const; + virtual JSObject *weakmapKeyDelegate(JSObject *proxy) const MOZ_OVERRIDE; }; /* @@ -257,16 +320,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 +338,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); @@ -293,46 +353,29 @@ class Proxy 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 boxedValue_unbox(JSContext *cx, HandleObject proxy, MutableHandleValue vp); 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 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 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 +386,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 +434,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 +459,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 +488,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 +513,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..4768a49624 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,10 +21,15 @@ #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 +#if (defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL)) || \ + (defined(JSGC_COMPACTING) && defined(DEBUG)) +# define JSGC_HASH_TABLE_CHECKS +#endif + namespace JS { class AutoIdVector; @@ -32,23 +38,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 +65,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 +76,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 +104,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,43 +118,38 @@ 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 - -#ifdef JS_THREADSAFE +}; + +/* 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; + typedef struct PRCallOnceType JSCallOnceType; -#else -typedef bool JSCallOnceType; -#endif typedef bool (*JSInitCallback)(void); /* @@ -182,6 +165,7 @@ namespace js { namespace gc { class StoreBuffer; void MarkPersistentRootedChains(JSTracer *); +void FinishPersistentRootedChains(JSRuntime *); } } @@ -194,33 +178,27 @@ namespace shadow { struct Runtime { /* Restrict zone access during Minor GC. */ - bool needsBarrier_; + bool needsIncrementalBarrier_; #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) + : needsIncrementalBarrier_(false) #ifdef JSGC_GENERATIONAL - , gcNurseryStart_(0) - , gcNurseryEnd_(0) , gcStoreBufferPtr_(storeBuffer) #endif {} - bool needsBarrier() const { - return needsBarrier_; + bool needsIncrementalBarrier() const { + return needsIncrementalBarrier_; } #ifdef JSGC_GENERATIONAL @@ -235,7 +213,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 +252,74 @@ 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 */ + WRAPVECTOR = -20, /* js::AutoWrapperVector */ + WRAPPER = -21, /* js::AutoWrapperRooter */ + OBJOBJHASHMAP=-22, /* js::AutoObjectObjectHashMap */ + OBJU32HASHMAP=-23, /* js::AutoObjectUnsigned32HashMap */ + OBJHASHSET = -24, /* js::AutoObjectHashSet */ + JSONPARSER = -25, /* js::JSONParser */ + CUSTOM = -26, /* js::CustomAutoRooter */ + FUNVECTOR = -27 /* 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..df59500fa5 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/jsversion.h @@ -41,14 +41,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..f55fea5301 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_.emplace(cx); + } + + inline JSObject *proto() const; + WrapperOptions &setProto(JSObject *protoArg) { + JS_ASSERT(proto_); + *proto_ = 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 *proto, - JSObject *parent, Wrapper *handler); + 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, Wrapper *handler); + static JSObject *Renew(JSContext *cx, JSObject *existing, JSObject *obj, const Wrapper *handler); - static Wrapper *wrapperHandler(JSObject *wrapper); + static const Wrapper *wrapperHandler(JSObject *wrapper); static JSObject *wrappedObject(JSObject *wrapper); @@ -62,68 +81,82 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler return mFlags; } - explicit Wrapper(unsigned flags, bool hasPrototype = false); + explicit MOZ_CONSTEXPR Wrapper(unsigned aFlags, bool aHasPrototype = false, + bool aHasSecurityPolicy = false) + : DirectProxyHandler(&family, aHasPrototype, aHasSecurityPolicy), + mFlags(aFlags) + { } - virtual ~Wrapper(); + virtual bool finalizeInBackground(Value priv) const MOZ_OVERRIDE; - virtual bool finalizeInBackground(Value priv) MOZ_OVERRIDE; + static const char family; + static const Wrapper singleton; + static const Wrapper singletonWithPrototype; - static Wrapper singleton; - static Wrapper singletonWithPrototype; + static JSObject *defaultProto; }; +inline JSObject * +WrapperOptions::proto() const +{ + return proto_ ? *proto_ : Wrapper::defaultProto; +} + /* Base class for all cross compartment wrapper handlers. */ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper { public: - CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false); - - virtual ~CrossCompartmentWrapper(); + explicit MOZ_CONSTEXPR CrossCompartmentWrapper(unsigned aFlags, bool aHasPrototype = false, + bool aHasSecurityPolicy = false) + : Wrapper(CROSS_COMPARTMENT | aFlags, aHasPrototype, aHasSecurityPolicy) + { } /* 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 boxedValue_unbox(JSContext *cx, HandleObject proxy, MutableHandleValue vp) 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 +172,31 @@ template class JS_FRIEND_API(SecurityWrapper) : public Base { public: - SecurityWrapper(unsigned flags); + explicit MOZ_CONSTEXPR SecurityWrapper(unsigned flags, bool hasPrototype = false) + : Base(flags, hasPrototype, /* hasSecurityPolicy = */ true) + { } - 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 boxedValue_unbox(JSContext *cx, HandleObject proxy, MutableHandleValue vp) 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 @@ -173,64 +212,53 @@ 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(); + explicit MOZ_CONSTEXPR DeadObjectProxy() + : BaseProxyHandler(&family) + { } /* 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 char family; + static const DeadObjectProxy singleton; }; extern JSObject * TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, - HandleObject wrappedProto, 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; + HandleObject parent); inline bool IsWrapper(JSObject *obj) { - return IsProxy(obj) && GetProxyHandler(obj)->family() == &sWrapperFamily; + return IsProxy(obj) && GetProxyHandler(obj)->family() == &Wrapper::family; } // Given a JSObject, returns that object stripped of wrappers. If @@ -278,34 +306,6 @@ 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. - AutoMaybeTouchDeadZones(JSContext *cx); - 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/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..a3ca984a77 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/AllocPolicy.h @@ -12,6 +12,9 @@ #ifndef mozilla_AllocPolicy_h #define mozilla_AllocPolicy_h +#include "mozilla/NullPtr.h" +#include "mozilla/TemplateLib.h" + #include #include @@ -24,14 +27,13 @@ namespace mozilla { * mechanism when OOM occurs. The concept modeled here is as follows: * * - public copy constructor, assignment, destructor - * - void* malloc_(size_t) + * - template T* pod_malloc(size_t) * Responsible for OOM reporting when null is returned. - * - void* calloc_(size_t) + * - template T* pod_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. + * - template T* pod_realloc(T*, size_t, size_t) + * Responsible for OOM reporting when null is returned. The old allocation + * size is passed in, in addition to the new allocation size requested. * - void free_(void*) * - void reportAllocOverflow() const * Called on allocation overflow (that is, an allocation implicitly tried @@ -49,14 +51,38 @@ 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: + template + T* pod_malloc(size_t aNumElems) + { + if (aNumElems & mozilla::tl::MulOverflowMask::value) + return nullptr; + return static_cast(malloc(aNumElems * sizeof(T))); + } + + template + T* pod_calloc(size_t aNumElems) + { + return static_cast(calloc(aNumElems, sizeof(T))); + } + template + T* pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize) + { + if (aNewSize & mozilla::tl::MulOverflowMask::value) + return nullptr; + return static_cast(realloc(aPtr, aNewSize * sizeof(T))); + } + + 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..676b82e416 --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/BinarySearch.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/. */ + +#ifndef mozilla_BinarySearch_h +#define mozilla_BinarySearch_h + +#include "mozilla/Assertions.h" + +#include + +namespace mozilla { + +/* + * The BinarySearch() 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); + * } + * + * The BinarySearchIf() version behaves similar, but takes |aComparator|, a + * functor to compare the values with, instead of a value to find. + * That functor should take one argument - the value to compare - and return an + * |int| with the comparison result: + * + * * 0, if the argument is equal to, + * * less than 0, if the argument is greater than, + * * greater than 0, if the argument is less than + * + * the value. + * + * Example: + * + * struct Comparator { + * int operator()(int val) const { + * if (mTarget < val) return -1; + * if (mValue > val) return 1; + * return 0; + * } + * Comparator(int target) : mTarget(target) {} + const int mTarget; + * }; + * + * Vector sortedInts = ... + * + * size_t match; + * if (BinarySearchIf(sortedInts, 0, sortedInts.length(), Comparator(13), &match)) { + * printf("found 13 at %lu\n", match); + * } + * + */ + +template +bool +BinarySearchIf(const Container& aContainer, size_t aBegin, size_t aEnd, + const Comparator& aCompare, size_t* aMatchOrInsertionPoint) +{ + MOZ_ASSERT(aBegin <= aEnd); + + size_t low = aBegin; + size_t high = aEnd; + while (high != low) { + size_t middle = low + (high - low) / 2; + + // Allow any intermediate type so long as it provides a suitable ordering + // relation. + const int result = aCompare(aContainer[middle]); + + if (result == 0) { + *aMatchOrInsertionPoint = middle; + return true; + } + + if (result < 0) { + high = middle; + } else { + low = middle + 1; + } + } + + *aMatchOrInsertionPoint = low; + return false; +} + +namespace detail { + +template +class BinarySearchDefaultComparator +{ +public: + BinarySearchDefaultComparator(const T& aTarget) + : mTarget(aTarget) + {} + + template + int operator()(const U& val) const { + if (mTarget == val) { + return 0; + } + + if (mTarget < val) { + return -1; + } + + return 1; + } + +private: + const T& mTarget; +}; + +} // namespace detail + +template +bool +BinarySearch(const Container& aContainer, size_t aBegin, size_t aEnd, + T aTarget, size_t* aMatchOrInsertionPoint) +{ + return BinarySearchIf(aContainer, aBegin, aEnd, + detail::BinarySearchDefaultComparator(aTarget), + aMatchOrInsertionPoint); +} + +} // 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..176e54dcf2 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) +AssertedCast(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..714e8a57ab 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..75b75df3f1 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,285 @@ 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; + + 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; +}; -const unsigned DoubleExponentBias = 1023; -const unsigned DoubleExponentShift = 52; +struct DoubleTypeTraits +{ + typedef uint64_t Bits; -const uint64_t DoubleSignBit = 0x8000000000000000ULL; -const uint64_t DoubleExponentBits = 0x7ff0000000000000ULL; -const uint64_t DoubleSignificandBits = 0x000fffffffffffffULL; + static const unsigned kExponentBias = 1023; + static const unsigned kExponentShift = 52; -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 Bits kSignBit = 0x8000000000000000ULL; + static const Bits kExponentBits = 0x7ff0000000000000ULL; + static const Bits kSignificandBits = 0x000fffffffffffffULL; +}; -static_assert((DoubleSignBit | DoubleExponentBits | DoubleSignificandBits) == - ~uint64_t(0), - "all bits accounted for"); +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 value is -0. */ + typedef FloatingPoint Traits; + typedef typename Traits::Bits Bits; + Bits bits = BitwiseCast(aValue); + return bits == Traits::kSignBit; +} + +/** + * Returns 0 if a float/double is NaN or infinite; + * otherwise, the float/double is returned. + */ +template +static MOZ_ALWAYS_INLINE T +ToZeroIfNonfinite(T aValue) { - /* Only the sign bit is set if the double is -0. */ - uint64_t bits = BitwiseCast(d); - return bits == DoubleSignBit; + return IsFinite(aValue) ? aValue : 0; } /** - * 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 +321,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 +330,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 +417,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..86052a7afe 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(reinterpret_cast(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(reinterpret_cast(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..28bfc1436e 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,30 @@ # 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 + +/** + * For printing size_t. + */ +#define PRIuSIZE PRIuPTR + #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..316343bc70 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Maybe.h @@ -4,160 +4,648 @@ * License, v. 2.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. */ +/* A class for optional values and in-place lazy construction. */ #ifndef mozilla_Maybe_h #define mozilla_Maybe_h #include "mozilla/Alignment.h" #include "mozilla/Assertions.h" +#include "mozilla/Attributes.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" -// For placement new -#include +#include // for placement new namespace mozilla { +struct Nothing { }; + /* - * 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. + * Maybe is a container class which contains either zero or one elements. It + * serves two roles. It can represent values which are *semantically* optional, + * augmenting a type with an explicit 'Nothing' value. In this role, it provides + * methods that make it easy to work with values that may be missing, along with + * equality and comparison operators so that Maybe values can be stored in + * containers. Maybe values can be constructed conveniently in expressions using + * type inference, as follows: + * + * void doSomething(Maybe aFoo) { + * if (aFoo) // Make sure that aFoo contains a value... + * aFoo->takeAction(); // and then use |aFoo->| to access it. + * } // |*aFoo| also works! + * + * doSomething(Nothing()); // Passes a Maybe containing no value. + * doSomething(Some(Foo(100))); // Passes a Maybe containing |Foo(100)|. + * + * You'll note that it's important to check whether a Maybe contains a value + * before using it, using conversion to bool, |isSome()|, or |isNothing()|. You + * can avoid these checks, and sometimes write more readable code, using + * |valueOr()|, |ptrOr()|, and |refOr()|, which allow you to retrieve the value + * in the Maybe and provide a default for the 'Nothing' case. You can also use + * |apply()| to call a function only if the Maybe holds a value, and |map()| to + * transform the value in the Maybe, returning another Maybe with a possibly + * different type. + * + * Maybe's other role is to support lazily constructing objects without using + * dynamic storage. A Maybe directly contains storage for a value, but it's + * empty by default. |emplace()|, as mentioned above, can be used to construct a + * value in Maybe's storage. The value a Maybe contains can be destroyed by + * calling |reset()|; this will happen automatically if a Maybe is destroyed + * while holding a value. * - * N.B. GCC seems to miss some optimizations with Maybe and may generate extra - * branches/loads/stores. Use with caution on hot paths. + * It's a common idiom in C++ to use a pointer as a 'Maybe' type, with a null + * value meaning 'Nothing' and any other value meaning 'Some'. You can convert + * from such a pointer to a Maybe value using 'ToMaybe()'. + * + * Maybe is inspired by similar types in the standard library of many other + * languages (e.g. Haskell's Maybe and Rust's Option). In the C++ world it's + * very similar to std::optional, which was proposed for C++14 and originated in + * Boost. The most important differences between Maybe and std::optional are: + * + * - std::optional may be compared with T. We deliberately forbid that. + * - std::optional allows in-place construction without a separate call to + * |emplace()| by using a dummy |in_place_t| value to tag the appropriate + * constructor. + * - std::optional has |valueOr()|, equivalent to Maybe's |valueOr()|, but + * lacks corresponding methods for |refOr()| and |ptrOr()|. + * - std::optional lacks |map()| and |apply()|, making it less suitable for + * functional-style code. + * - std::optional lacks many convenience functions that Maybe has. Most + * unfortunately, it lacks equivalents of the type-inferred constructor + * functions |Some()| and |Nothing()|. + * + * N.B. GCC has missed optimizations with Maybe in the past and may generate + * extra branches/loads/stores. Use with caution on hot paths; it's not known + * whether or not this is still a problem. */ template class Maybe { - AlignedStorage2 storage; - bool constructed; + typedef void (Maybe::* ConvertibleToBool)(float*****, double*****); + void nonNull(float*****, double*****) {} - T& asT() { return *storage.addr(); } + bool mIsSome; + AlignedStorage2 mStorage; - public: - Maybe() { constructed = false; } - ~Maybe() { if (constructed) asT().~T(); } +public: + typedef T ValueType; - bool empty() const { return !constructed; } + Maybe() : mIsSome(false) { } + ~Maybe() { reset(); } - void construct() { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(); - constructed = true; + MOZ_IMPLICIT Maybe(Nothing) : mIsSome(false) { } + + Maybe(const Maybe& aOther) + : mIsSome(false) + { + if (aOther.mIsSome) { + emplace(*aOther); } + } - template - void construct(const T1& t1) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1); - constructed = true; + Maybe(Maybe&& aOther) + : mIsSome(false) + { + if (aOther.mIsSome) { + emplace(Move(*aOther)); + aOther.reset(); } + } - template - void construct(const T1& t1, const T2& t2) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2); - constructed = true; + Maybe& operator=(const Maybe& aOther) + { + if (&aOther != this) { + if (aOther.mIsSome) { + if (mIsSome) { + // XXX(seth): The correct code for this branch, below, can't be used + // due to a bug in Visual Studio 2010. See bug 1052940. + /* + ref() = aOther.ref(); + */ + reset(); + emplace(*aOther); + } else { + emplace(*aOther); + } + } else { + reset(); + } } + return *this; + } + + Maybe& operator=(Maybe&& aOther) + { + MOZ_ASSERT(this != &aOther, "Self-moves are prohibited"); - template - void construct(const T1& t1, const T2& t2, const T3& t3) { - MOZ_ASSERT(!constructed); - ::new (storage.addr()) T(t1, t2, t3); - constructed = true; + if (aOther.mIsSome) { + if (mIsSome) { + ref() = Move(aOther.ref()); + } else { + emplace(Move(*aOther)); + } + aOther.reset(); + } else { + reset(); } - 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; + return *this; + } + + /* Methods that check whether this Maybe contains a value */ + operator ConvertibleToBool() const { return mIsSome ? &Maybe::nonNull : 0; } + bool isSome() const { return mIsSome; } + bool isNothing() const { return !mIsSome; } + + /* Returns the contents of this Maybe by value. Unsafe unless |isSome()|. */ + T value() const + { + MOZ_ASSERT(mIsSome); + return ref(); + } + + /* + * Returns the contents of this Maybe by value. If |isNothing()|, returns + * the default value provided. + */ + template + T valueOr(V&& aDefault) const + { + if (isSome()) { + return ref(); } + return Forward(aDefault); + } - 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; + /* + * Returns the contents of this Maybe by value. If |isNothing()|, returns + * the value returned from the function or functor provided. + */ + template + T valueOrFrom(F&& aFunc) const + { + if (isSome()) { + return ref(); } + return aFunc(); + } + + /* Returns the contents of this Maybe by pointer. Unsafe unless |isSome()|. */ + T* ptr() + { + MOZ_ASSERT(mIsSome); + return &ref(); + } + + const T* ptr() const + { + MOZ_ASSERT(mIsSome); + return &ref(); + } - 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; + /* + * Returns the contents of this Maybe by pointer. If |isNothing()|, + * returns the default value provided. + */ + T* ptrOr(T* aDefault) + { + if (isSome()) { + return ptr(); } + return aDefault; + } - 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; + const T* ptrOr(const T* aDefault) const + { + if (isSome()) { + return ptr(); } + return aDefault; + } - 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; + /* + * Returns the contents of this Maybe by pointer. If |isNothing()|, + * returns the value returned from the function or functor provided. + */ + template + T* ptrOrFrom(F&& aFunc) + { + if (isSome()) { + return ptr(); } + return aFunc(); + } - 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 + const T* ptrOrFrom(F&& aFunc) const + { + if (isSome()) { + return ptr(); } + return aFunc(); + } - 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* operator->() + { + MOZ_ASSERT(mIsSome); + return ptr(); + } + + const T* operator->() const + { + MOZ_ASSERT(mIsSome); + return ptr(); + } + + /* Returns the contents of this Maybe by ref. Unsafe unless |isSome()|. */ + T& ref() + { + MOZ_ASSERT(mIsSome); + return *mStorage.addr(); + } + + const T& ref() const + { + MOZ_ASSERT(mIsSome); + return *mStorage.addr(); + } + + /* + * Returns the contents of this Maybe by ref. If |isNothing()|, returns + * the default value provided. + */ + T& refOr(T& aDefault) + { + if (isSome()) { + return ref(); } + return aDefault; + } - T* addr() { - MOZ_ASSERT(constructed); - return &asT(); + const T& refOr(const T& aDefault) const + { + if (isSome()) { + return ref(); } + return aDefault; + } - T& ref() { - MOZ_ASSERT(constructed); - return asT(); + /* + * Returns the contents of this Maybe by ref. If |isNothing()|, returns the + * value returned from the function or functor provided. + */ + template + T& refOrFrom(F&& aFunc) + { + if (isSome()) { + return ref(); } + return aFunc(); + } - const T& ref() const { - MOZ_ASSERT(constructed); - return const_cast(this)->asT(); + template + const T& refOrFrom(F&& aFunc) const + { + if (isSome()) { + return ref(); } + return aFunc(); + } - void destroy() { - ref().~T(); - constructed = false; + T& operator*() + { + MOZ_ASSERT(mIsSome); + return ref(); + } + + const T& operator*() const + { + MOZ_ASSERT(mIsSome); + return ref(); + } + + /* If |isSome()|, runs the provided function or functor on the contents of + * this Maybe. */ + template + void apply(F&& aFunc) + { + if (isSome()) { + aFunc(ref()); + } + } + + template + void apply(F&& aFunc) const + { + if (isSome()) { + aFunc(ref()); + } + } + + /* Variant of |apply()| that takes an additional argument for the function. */ + template + void apply(F&& aFunc, A&& aArg) + { + if (isSome()) { + aFunc(ref(), Forward(aArg)); + } + } + + template + void apply(F&& aFunc, A&& aArg) const + { + if (isSome()) { + aFunc(ref(), Forward(aArg)); + } + } + + /* + * If |isSome()|, runs the provided function and returns the result wrapped + * in a Maybe. If |isNothing()|, returns an empty Maybe value. + */ + template + Maybe map(R(*aFunc)(T&)) + { + if (isSome()) { + Maybe val; + val.emplace(aFunc(ref())); + return val; } + return Maybe(); + } - void destroyIfConstructed() { - if (!empty()) - destroy(); + template + Maybe map(R(*aFunc)(const T&)) const + { + if (isSome()) { + Maybe val; + val.emplace(aFunc(ref())); + return val; } + return Maybe(); + } + + /* Variant of |map()| that takes an additional argument for the function. */ + template + Maybe map(R(*aFunc)(T&, FA), A&& aArg) + { + if (isSome()) { + Maybe val; + val.emplace(aFunc(ref(), Forward(aArg))); + return val; + } + return Maybe(); + } + + template + Maybe map(R(*aFunc)(const T&, FA), A&& aArg) const + { + if (isSome()) { + Maybe val; + val.emplace(aFunc(ref(), Forward(aArg))); + return val; + } + return Maybe(); + } + + /* If |isSome()|, empties this Maybe and destroys its contents. */ + void reset() + { + if (isSome()) { + ref().~T(); + mIsSome = false; + } + } + + /* + * Constructs a T value in-place in this empty Maybe's storage. The + * arguments to |emplace()| are the parameters to T's constructor. + * + * WARNING: You can't pass a literal nullptr to these methods without + * hitting GCC 4.4-only (and hence B2G-only) compile errors. + */ + void emplace() + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(); + mIsSome = true; + } + + template + void emplace(T1&& t1) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2)); + mIsSome = true; + } - private: - Maybe(const Maybe& other) MOZ_DELETE; - const Maybe& operator=(const Maybe& other) MOZ_DELETE; + template + void emplace(T1&& t1, T2&& t2, T3&& t3) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5, T6&& t6) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5), Forward(t6)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5, T6&& t6, + T7&& t7) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5), Forward(t6), + Forward(t7)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5, T6&& t6, + T7&& t7, T8&& t8) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5), Forward(t6), + Forward(t7), Forward(t8)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5, T6&& t6, + T7&& t7, T8&& t8, T9&& t9) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5), Forward(t6), + Forward(t7), Forward(t8), Forward(t9)); + mIsSome = true; + } + + template + void emplace(T1&& t1, T2&& t2, T3&& t3, T4&& t4, T5&& t5, T6&& t6, + T7&& t7, T8&& t8, T9&& t9, T10&& t10) + { + MOZ_ASSERT(!mIsSome); + ::new (mStorage.addr()) T(Forward(t1), Forward(t2), Forward(t3), + Forward(t4), Forward(t5), Forward(t6), + Forward(t7), Forward(t8), Forward(t9), + Forward(t10)); + mIsSome = true; + } }; +/* + * Some() creates a Maybe value containing the provided T value. If T has a + * move constructor, it's used to make this as efficient as possible. + * + * Some() selects the type of Maybe it returns by removing any const, volatile, + * or reference qualifiers from the type of the value you pass to it. This gives + * it more intuitive behavior when used in expressions, but it also means that + * if you need to construct a Maybe value that holds a const, volatile, or + * reference value, you need to use emplace() instead. + */ +template +Maybe::Type>::Type> +Some(T&& aValue) +{ + typedef typename RemoveCV::Type>::Type U; + Maybe value; + value.emplace(Forward(aValue)); + return value; +} + +template +Maybe::Type>::Type> +ToMaybe(T* aPtr) +{ + if (aPtr) { + return Some(*aPtr); + } + return Nothing(); +} + +/* + * Two Maybe values are equal if + * - both are Nothing, or + * - both are Some, and the values they contain are equal. + */ +template bool +operator==(const Maybe& aLHS, const Maybe& aRHS) +{ + if (aLHS.isNothing() != aRHS.isNothing()) { + return false; + } + return aLHS.isNothing() || *aLHS == *aRHS; +} + +template bool +operator!=(const Maybe& aLHS, const Maybe& aRHS) +{ + return !(aLHS == aRHS); +} + +/* + * We support comparison to Nothing to allow reasonable expressions like: + * if (maybeValue == Nothing()) { ... } + */ +template bool +operator==(const Maybe& aLHS, const Nothing& aRHS) +{ + return aLHS.isNothing(); +} + +template bool +operator!=(const Maybe& aLHS, const Nothing& aRHS) +{ + return !(aLHS == aRHS); +} + +template bool +operator==(const Nothing& aLHS, const Maybe& aRHS) +{ + return aRHS.isNothing(); +} + +template bool +operator!=(const Nothing& aLHS, const Maybe& aRHS) +{ + return !(aLHS == aRHS); +} + +/* + * Maybe values are ordered in the same way T values are ordered, except that + * Nothing comes before anything else. + */ +template bool +operator<(const Maybe& aLHS, const Maybe& aRHS) +{ + if (aLHS.isNothing()) { + return aRHS.isSome(); + } + if (aRHS.isNothing()) { + return false; + } + return *aLHS < *aRHS; +} + +template bool +operator>(const Maybe& aLHS, const Maybe& aRHS) +{ + return !(aLHS < aRHS || aLHS == aRHS); +} + +template bool +operator<=(const Maybe& aLHS, const Maybe& aRHS) +{ + return aLHS < aRHS || aLHS == aRHS; +} + +template bool +operator>=(const Maybe& aLHS, const Maybe& aRHS) +{ + return !(aLHS < aRHS); +} + } // namespace mozilla #endif /* mozilla_Maybe_h */ 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..6ea0efa17b 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,16 @@ #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 +65,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..0cb6b1cd29 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,166 +385,11 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + 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 -{ - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; - } - - bool dead; - static int numDestroyed; -}; -int Foo::numDestroyed; - -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::numDestroyed); - { - RefPtr f = new Foo(); - MOZ_ASSERT(f->refCount() == 1); - } - MOZ_ASSERT(1 == Foo::numDestroyed); - - { - RefPtr f1 = NewFoo(); - RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); - } - MOZ_ASSERT(3 == Foo::numDestroyed); - - { - RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); - } - MOZ_ASSERT(4 == Foo::numDestroyed); - - { - RefPtr f1; - { - f1 = new Foo(); - RefPtr f2(f1); - RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); - } - MOZ_ASSERT(4 == Foo::numDestroyed); - } - MOZ_ASSERT(5 == Foo::numDestroyed); - - { - RefPtr f = new Foo(); - f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); - } - - { - RefPtr f = new Foo(); - GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); - } - MOZ_ASSERT(8 == Foo::numDestroyed); - - { - RefPtr f = new Foo(); - GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); - } - MOZ_ASSERT(9 == Foo::numDestroyed); - - { - RefPtr f = new Foo(); - GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); - } - MOZ_ASSERT(11 == Foo::numDestroyed); - - { - RefPtr f = new Foo(); - GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); - } - MOZ_ASSERT(12 == Foo::numDestroyed); - - { - RefPtr f1 = new Bar(); - } - MOZ_ASSERT(13 == Foo::numDestroyed); - - { - RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); - } - MOZ_ASSERT(13 == Foo::numDestroyed); - - return 0; -} - -#endif - #endif /* mozilla_RefPtr_h */ 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..a16f417284 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/Scoped.h @@ -4,12 +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/. */ -/* A number of structures to simplify scope-based RAII management. */ +/* DEPRECATED: Use UniquePtr.h instead. */ #ifndef mozilla_Scoped_h #define mozilla_Scoped_h /* + * DEPRECATED: Use UniquePtr.h instead. + * * 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 @@ -23,8 +25,8 @@ * |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. + * + * |ScopedDeleteArray| is removed in favor of |UniquePtr|. * * The general scenario for each of the RAII classes is the following: * @@ -52,8 +54,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 +66,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 +80,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(); + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; + bool operator==(const Resource& aOther) const { return mValue == aOther; } - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + /* + * 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 }; /* @@ -163,26 +186,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 +230,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,23 +245,10 @@ 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) -/* - * 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* ptr) { delete [] ptr; } -}; -SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) - /* * MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE makes it easy to create scoped * pointers for types with custom deleters; just overload @@ -250,21 +272,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..f620c4ddda 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,247 @@ class SplayTreeNode template class SplayTree { - T* root; - T* freeList; - - public: - SplayTree() - : root(nullptr), freeList(nullptr) - {} + T* mRoot; - 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); + 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); + 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; + } + + 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); + } + + // For testing purposes only. + void checkCoherency() + { + checkCoherency(mRoot, nullptr); + } + +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; + } + } 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; } - node->parent = parent->parent; - parent->parent = node; - if (T* grandparent = node->parent) { - if (grandparent->left == parent) - grandparent->left = node; - else - grandparent->right = node; + 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) + { + if (mRoot) { + MOZ_RELEASE_ASSERT(!mRoot->mParent); + } + if (!aNode) { + MOZ_RELEASE_ASSERT(!mRoot); return nullptr; -#endif } + if (!aNode->mParent) { + MOZ_RELEASE_ASSERT(aNode == mRoot); + } + if (aMinimum) { + MOZ_RELEASE_ASSERT(Comparator::compare(*aMinimum, *aNode) < 0); + } + if (aNode->mLeft) { + MOZ_RELEASE_ASSERT(aNode->mLeft->mParent == aNode); + T* leftMaximum = checkCoherency(aNode->mLeft, aMinimum); + MOZ_RELEASE_ASSERT(Comparator::compare(*leftMaximum, *aNode) < 0); + } + if (aNode->mRight) { + MOZ_RELEASE_ASSERT(aNode->mRight->mParent == aNode); + return checkCoherency(aNode->mRight, aNode); + } + return aNode; + } - 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..c288ee664c --- /dev/null +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/UniquePtr.h @@ -0,0 +1,805 @@ +/* -*- 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 + * + * (Note that changing a UniquePtr to store a direct |new| expression is + * permitted, but usually you should use MakeUnique, defined at the end of this + * header.) + * + * 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 mTuple; + + Pointer& ptr() { return mTuple.first(); } + const Pointer& ptr() const { return mTuple.first(); } + + DeleterType& del() { return mTuple.second(); } + const DeleterType& del() const { return mTuple.second(); } + +public: + /** + * Construct a UniquePtr containing |nullptr|. + */ + MOZ_CONSTEXPR UniquePtr() + : mTuple(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 |aPtr|. + */ + explicit UniquePtr(Pointer aPtr) + : mTuple(aPtr, DeleterType()) + { + static_assert(!IsPointer::value, "must provide a deleter instance"); + static_assert(!IsReference::value, "must provide a deleter instance"); + } + + UniquePtr(Pointer aPtr, + typename Conditional::value, + D, + const D&>::Type aD1) + : mTuple(aPtr, aD1) + {} + + // 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* aPtr) { free(aPtr); } + // }; + // + // 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 aPtr, + typename RemoveReference::Type&& aD2) + : mTuple(aPtr, Move(aD2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + + UniquePtr(UniquePtr&& aOther) + : mTuple(aOther.release(), Forward(aOther.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type aDummy = 0) + : mTuple(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&& aOther, + typename EnableIf::Pointer, + Pointer>::value && + !IsArray::value && + (IsReference::value + ? IsSame::value + : IsConvertible::value), + int>::Type aDummy = 0) + : mTuple(aOther.release(), Forward(aOther.getDeleter())) + { + } + + ~UniquePtr() { reset(nullptr); } + + UniquePtr& operator=(UniquePtr&& aOther) + { + reset(aOther.release()); + getDeleter() = Forward(aOther.getDeleter()); + return *this; + } + + template + UniquePtr& operator=(UniquePtr&& aOther) + { + static_assert(IsConvertible::Pointer, + Pointer>::value, + "incompatible UniquePtr pointees"); + static_assert(!IsArray::value, + "can't assign from UniquePtr holding an array"); + + reset(aOther.release()); + getDeleter() = Forward(aOther.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT aNull) + { + MOZ_ASSERT(aNull == 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 aPtr = Pointer()) + { + Pointer old = ptr(); + ptr() = aPtr; + if (old != nullptr) { + getDeleter()(old); + } + } + + void swap(UniquePtr& aOther) + { + mTuple.swap(aOther.mTuple); + } + +private: + UniquePtr(const UniquePtr& aOther) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& aOther) 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 mTuple; + +public: + /** + * Construct a UniquePtr containing nullptr. + */ + MOZ_CONSTEXPR UniquePtr() + : mTuple(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 |aPtr|. + */ + explicit UniquePtr(Pointer aPtr) + : mTuple(aPtr, 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&& aU, + typename EnableIf::value && + IsConvertible::value, + int>::Type aDummy = 0) + MOZ_DELETE; + +public: + UniquePtr(Pointer aPtr, + typename Conditional::value, + D, + const D&>::Type aD1) + : mTuple(aPtr, aD1) + {} + + // 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 aPtr, + typename RemoveReference::Type&& aD2) + : mTuple(aPtr, Move(aD2)) + { + static_assert(!IsReference::value, + "rvalue deleter can't be stored by reference"); + } + +private: + // Forbidden for the same reasons as stated above. + template + UniquePtr(U&& aU, V&& aV, + typename EnableIf::value && + IsConvertible::value, + int>::Type aDummy = 0) + MOZ_DELETE; + +public: + UniquePtr(UniquePtr&& aOther) + : mTuple(aOther.release(), Forward(aOther.getDeleter())) + {} + + template + UniquePtr(N, + typename EnableIf::value, int>::Type aDummy = 0) + : mTuple(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&& aOther) + { + reset(aOther.release()); + getDeleter() = Forward(aOther.getDeleter()); + return *this; + } + + UniquePtr& operator=(NullptrT) + { + reset(); + return *this; + } + + T& operator[](decltype(sizeof(int)) aIndex) const { return get()[aIndex]; } + Pointer get() const { return mTuple.first(); } + + DeleterType& getDeleter() { return mTuple.second(); } + const DeleterType& getDeleter() const { return mTuple.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 = mTuple.first(); + mTuple.first() = nullptr; + return p; + } + + void reset(Pointer aPtr = Pointer()) + { + Pointer old = mTuple.first(); + mTuple.first() = aPtr; + if (old != nullptr) { + mTuple.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 aDummy = 0) + MOZ_DELETE; + +public: + void swap(UniquePtr& aOther) { mTuple.swap(aOther.mTuple); } + +private: + UniquePtr(const UniquePtr& aOther) MOZ_DELETE; // construct using Move()! + void operator=(const UniquePtr& aOther) 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& aOther, + typename EnableIf::value, + int>::Type aDummy = 0) + {} + + void operator()(T* aPtr) const + { + static_assert(sizeof(T) > 0, "T must be complete"); + delete aPtr; + } +}; + +/** A default deletion policy using operator delete[]. */ +template +class DefaultDelete +{ +public: + MOZ_CONSTEXPR DefaultDelete() {} + + void operator()(T* aPtr) const + { + static_assert(sizeof(T) > 0, "T must be complete"); + delete[] aPtr; + } + +private: + template + void operator()(U* aPtr) const MOZ_DELETE; +}; + +template +void +Swap(UniquePtr& aX, UniquePtr& aY) +{ + aX.swap(aY); +} + +template +bool +operator==(const UniquePtr& aX, const UniquePtr& aY) +{ + return aX.get() == aY.get(); +} + +template +bool +operator!=(const UniquePtr& aX, const UniquePtr& aY) +{ + return aX.get() != aY.get(); +} + +template +bool +operator==(const UniquePtr& aX, NullptrT aNull) +{ + MOZ_ASSERT(aNull == nullptr); + return !aX; +} + +template +bool +operator==(NullptrT aNull, const UniquePtr& aX) +{ + MOZ_ASSERT(aNull == nullptr); + return !aX; +} + +template +bool +operator!=(const UniquePtr& aX, NullptrT aNull) +{ + MOZ_ASSERT(aNull == nullptr); + return bool(aX); +} + +template +bool +operator!=(NullptrT aNull, const UniquePtr& aX) +{ + MOZ_ASSERT(aNull == nullptr); + return bool(aX); +} + +// 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 + +/** + * MakeUnique is a helper function for allocating new'd objects and arrays, + * returning a UniquePtr containing the resulting pointer. The semantics of + * MakeUnique(...) are as follows. + * + * If Type is an array T[n]: + * Disallowed, deleted, no overload for you! + * If Type is an array T[]: + * MakeUnique(size_t) is the only valid overload. The pointer returned + * is as if by |new T[n]()|, which value-initializes each element. (If T + * isn't a class type, this will zero each element. If T is a class type, + * then roughly speaking, each element will be constructed using its default + * constructor. See C++11 [dcl.init]p7 for the full gory details.) + * If Type is non-array T: + * The arguments passed to MakeUnique(...) are forwarded into a + * |new T(...)| call, initializing the T as would happen if executing + * |T(...)|. (Note: literal nullptr must not be provided as an argument to + * MakeUnique, because nullptr may be emulated. See Move.h for details.) + * + * There are various benefits to using MakeUnique instead of |new| expressions. + * + * First, MakeUnique eliminates use of |new| from code entirely. If objects are + * only created through UniquePtr, then (assuming all explicit release() calls + * are safe, including transitively, and no type-safety casting funniness) + * correctly maintained ownership of the UniquePtr guarantees no leaks are + * possible. (This pays off best if a class is only ever created through a + * factory method on the class, using a private constructor.) + * + * Second, initializing a UniquePtr using a |new| expression requires renaming + * the new'd type, whereas MakeUnique in concert with the |auto| keyword names + * it only once: + * + * UniquePtr ptr1(new char()); // repetitive + * auto ptr2 = MakeUnique(); // shorter + * + * Of course this assumes the reader understands the operation MakeUnique + * performs. In the long run this is probably a reasonable assumption. In the + * short run you'll have to use your judgment about what readers can be expected + * to know, or to quickly look up. + * + * Third, a call to MakeUnique can be assigned directly to a UniquePtr. In + * contrast you can't assign a pointer into a UniquePtr without using the + * cumbersome reset(). + * + * UniquePtr p; + * p = new char; // ERROR + * p.reset(new char); // works, but fugly + * p = MakeUnique(); // preferred + * + * (And third, although not relevant to Mozilla: MakeUnique is exception-safe. + * An exception thrown after |new T| succeeds will leak that memory, unless the + * pointer is assigned to an object that will manage its ownership. UniquePtr + * ably serves this function.) + */ + +// We don't have variadic template support everywhere, so just hard-code arities +// 0-8 for now. If you need more arguments, feel free to add the extra +// overloads (and deletions for the T = E[N] case). +// +// 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&& aA1) +{ + return UniquePtr(new T(Forward(aA1))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& aA1, A2&& aA2) +{ + return UniquePtr(new T(Forward(aA1), Forward(aA2))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3) +{ + return UniquePtr(new T(Forward(aA1), Forward(aA2), + Forward(aA3))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4) +{ + return UniquePtr(new T(Forward(aA1), Forward(aA2), + Forward(aA3), Forward(aA4))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4, A5&& aA5) +{ + return UniquePtr(new T(Forward(aA1), Forward(aA2), + Forward(aA3), Forward(aA4), + Forward(aA5))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), + Forward(a3), Forward(a4), + Forward(a5), Forward(a6))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), + Forward(a3), Forward(a4), + Forward(a5), Forward(a6), + Forward(a7))); +} + +template +typename detail::UniqueSelector::SingleObject +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7, + A8&& a8) +{ + return UniquePtr(new T(Forward(a1), Forward(a2), + Forward(a3), Forward(a4), + Forward(a5), Forward(a6), + Forward(a7), Forward(a8))); +} + +template +typename detail::UniqueSelector::UnknownBound +MakeUnique(decltype(sizeof(int)) aN) +{ + typedef typename RemoveExtent::Type ArrayType; + return UniquePtr(new ArrayType[aN]()); +} + +template +typename detail::UniqueSelector::KnownBound +MakeUnique() MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& aA1) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& aA1, A2&& aA2) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4, A5&& aA5) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, + A6&& a6) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, + A7&& a7) MOZ_DELETE; + +template +typename detail::UniqueSelector::KnownBound +MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, + A7&& a7, A8&& a8) 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..3e7745dea1 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 = aV.template pod_malloc(aNewCap); + 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,69 @@ 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)); + T* newbuf = aV.template pod_realloc(aV.mBegin, aV.mCapacity, aNewCap); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -199,368 +227,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 +616,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 +656,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 +684,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 = this->template pod_malloc(aNewCap); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -666,15 +714,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 +736,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 +773,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 +794,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -755,34 +804,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 = this->template pod_malloc(aRequest); + 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 +843,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 +928,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 @@ -1059,20 +1135,21 @@ VectorBase::extractRawBuffer() { T* ret; if (usingInlineStorage()) { - ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + ret = this->template pod_malloc(mLength); + 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 +1157,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 +1192,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 +1258,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..58960ad617 100644 --- a/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h +++ b/frameworks/js-bindings/external/spidermonkey/include/ios/mozilla/WeakPtr.h @@ -14,32 +14,40 @@ * 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 + * // Get weak pointers to ptr. The first time a weak pointer + * // is obtained, 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(); + * WeakPtr weak = ptr; + * WeakPtr other = ptr; * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -59,107 +67,143 @@ #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; +template class WeakPtr; +template class SupportsWeakPtr; 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 +// SupportsWeakPtr. 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 mozilla::SupportsWeakPtr; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail -template -class SupportsWeakPtrBase +template +class SupportsWeakPtr { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +protected: + ~SupportsWeakPtr() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtr"); + if (mSelfReferencingWeakPtr) { + mSelfReferencingWeakPtr.mRef->detach(); } + } - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); +private: + const WeakPtr& SelfReferencingWeakPtr() + { + if (!mSelfReferencingWeakPtr) { + mSelfReferencingWeakPtr.mRef = new detail::WeakReference(static_cast(this)); } + return mSelfReferencingWeakPtr; + } + + const WeakPtr& SelfReferencingWeakPtr() const + { + const WeakPtr& p = const_cast(this)->SelfReferencingWeakPtr(); + return reinterpret_cast&>(p); + } - private: - friend class WeakPtrBase; + friend class WeakPtr; + friend class WeakPtr; - RefPtr weakRef; + WeakPtr mSelfReferencingWeakPtr; }; template -class SupportsWeakPtr : public SupportsWeakPtrBase > +class WeakPtr { -}; + typedef detail::WeakReference WeakReference; -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: + WeakPtr& operator=(const WeakPtr& aOther) + { + mRef = aOther.mRef; + return *this; + } - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + WeakPtr(const WeakPtr& aOther) + { + *this = aOther; + } - T* operator->() const { - return ref->get(); - } + WeakPtr& operator=(T* aOther) + { + return *this = aOther->SelfReferencingWeakPtr(); + } - T* get() const { - return ref->get(); - } + MOZ_IMPLICIT WeakPtr(T* aOther) + { + *this = aOther; + } - private: - friend class SupportsWeakPtrBase; + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtr() : mRef(new WeakReference(nullptr)) {} - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - RefPtr ref; -}; + T* operator->() const { return mRef->get(); } -template -class WeakPtr : public WeakPtrBase > -{ - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + T* get() const { return mRef->get(); } + +private: + friend class SupportsWeakPtr; + + explicit WeakPtr(const RefPtr& aOther) : mRef(aOther) {} + + RefPtr mRef; }; } // 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/ios/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/ios/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/ios/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/linux/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/linux/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/linux/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/mac/js/Tracer.h b/frameworks/js-bindings/external/spidermonkey/include/win32/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/win32/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/win32/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/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 abd74363c5..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() { @@ -1251,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 @@ -1318,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) { @@ -1366,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) { @@ -1510,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); } @@ -1551,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); } @@ -1566,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(); } }; /* @@ -1598,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); } }; @@ -1628,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) { @@ -1642,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; } @@ -1750,7 +1887,7 @@ inline Anchor::~Anchor() } #endif -#ifdef DEBUG +#ifdef JS_DEBUG namespace detail { struct ValueAlignmentTester { char c; JS::Value v; }; @@ -1762,7 +1899,7 @@ static_assert(sizeof(LayoutAlignmentTester) == 16, "jsval_layout must be 16-byte-aligned"); } // namespace detail -#endif /* DEBUG */ +#endif /* JS_DEBUG */ } // namespace JS @@ -1778,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) { @@ -1855,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) { @@ -1895,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 @@ -1941,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 @@ -1961,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/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/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..5891cd0238 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/wp8/arm/mozjs-33.dll b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/arm/mozjs-33.dll new file mode 100644 index 0000000000..93375b4871 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..4ce310cc3d 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..9da6630d45 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..4e18739d8e Binary files /dev/null and b/frameworks/js-bindings/external/spidermonkey/prebuilt/wp8/win32/mozjs-33.lib differ diff --git a/samples/js-moonwarriors/project/Classes/AppDelegate.cpp b/samples/js-moonwarriors/project/Classes/AppDelegate.cpp index 08f7a7557d..4ce9e1f858 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) + 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..77c031f1d6 100644 --- a/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj +++ b/samples/js-moonwarriors/project/proj.win32/js-moonwarriors.vcxproj @@ -102,11 +102,11 @@ 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) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) true Windows @@ -161,11 +161,11 @@ 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) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) Windows MachineX86 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.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..a18e7cd68f --- /dev/null +++ b/samples/js-moonwarriors/project/proj.wp8-xaml/js-moonwarriorsComponent/js-moonwarriorsComponent.vcxproj @@ -0,0 +1,233 @@ + + + + + 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) + + + 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) + + + 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 + + + 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) + + + 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/src/Enemy.js b/samples/js-moonwarriors/src/Enemy.js index 71a22d84a6..d448119619 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 ? res.explodeEffect_wav : res.explodeEffect_mp3); } this.visible = false; this.active = false; diff --git a/samples/js-moonwarriors/src/GameLayer.js b/samples/js-moonwarriors/src/GameLayer.js index 9f6f98fc7f..ccc10e0e2d 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 ? 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 f4c8a19f8c..faa60b6f52 100755 --- a/samples/js-moonwarriors/src/GameOver.js +++ b/samples/js-moonwarriors/src/GameOver.js @@ -113,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 ? 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 15b98a0638..0098791d8e 100755 --- a/samples/js-moonwarriors/src/Resource.js +++ b/samples/js-moonwarriors/src/Resource.js @@ -33,22 +33,27 @@ 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', @@ -76,6 +81,7 @@ var g_mainmenu = [ res.b01_plist, res.mainMainMusic_mp3, res.mainMainMusic_ogg, + res.mainMainMusic_wav, res.menuTitle_png, res.textureTransparentPack_plist, res.textureTransparentPack_png @@ -102,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 2a1bafe90c..f6da65e199 100755 --- a/samples/js-moonwarriors/src/SettingsLayer.js +++ b/samples/js-moonwarriors/src/SettingsLayer.js @@ -104,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 ? 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..a30e87e388 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 ? 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 ef8ff862bc..39d05ec42a 100755 --- a/samples/js-moonwarriors/src/SysMenu.js +++ b/samples/js-moonwarriors/src/SysMenu.js @@ -116,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 ? res.mainMainMusic_wav : res.mainMainMusic_mp3, true); } return true; @@ -156,7 +156,10 @@ var SysMenu = cc.Layer.extend({ }, onButtonEffect:function(){ if (MW.SOUND) { - var s = cc.audioEngine.playEffect(res.buttonEffet_mp3); + //TODO: why buttonEffet_wav play failed on wp8? + //var s = cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 ? res.buttonEffet_wav : res.buttonEffet_mp3); + if(cc.sys.os !== cc.sys.OS_WP8) + var s = cc.audioEngine.playEffect(res.buttonEffet_mp3); } } }); 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/project.json b/samples/js-tests/project.json index 4d76f8d2e8..0108f0e89e 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", diff --git a/samples/js-tests/project/Classes/AppDelegate.cpp b/samples/js-tests/project/Classes/AppDelegate.cpp index 09682b8dbf..6ee0225dfa 100644 --- a/samples/js-tests/project/Classes/AppDelegate.cpp +++ b/samples/js-tests/project/Classes/AppDelegate.cpp @@ -7,6 +7,8 @@ #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 "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 +24,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 +37,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 +67,11 @@ bool AppDelegate::applicationDidFinishLaunching() auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { +#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) + glview = cocos2d::GLViewImpl::create("js-tests"); +#else glview = cocos2d::GLViewImpl::createWithRect("js-tests", Rect(0,0,900,640)); +#endif director->setOpenGLView(glview); } @@ -70,7 +81,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 +103,9 @@ 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); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(register_all_pluginx_protocols); @@ -104,6 +117,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..0843735ebf 100644 --- a/samples/js-tests/project/proj.win32/js-tests.vcxproj +++ b/samples/js-tests/project/proj.win32/js-tests.vcxproj @@ -102,11 +102,11 @@ 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) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) true Windows @@ -163,11 +163,11 @@ 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) + libcurl_imp.lib;mozjs-33.lib;ws2_32.lib;sqlite3.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) Windows MachineX86 @@ -189,10 +189,14 @@ copy "$(ProjectDir)..\..\project.json" "$(OutDir)\js-tests-res" + + + + 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.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-tests/js-tests.csproj.user b/samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.csproj.user new file mode 100644 index 0000000000..ffd0bfc785 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.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-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..dcfc6cedc0 --- /dev/null +++ b/samples/js-tests/project/proj.wp8-xaml/js-testsComponent/js-testsComponent.vcxproj @@ -0,0 +1,235 @@ + + + + + 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) + + + 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) + + + 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 + + + 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) + + + 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/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/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/UIEditorTest/2.1/res/MP3/2.wav b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MP3/2.wav new file mode 100644 index 0000000000..9024ed5e76 Binary files /dev/null and b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MP3/2.wav differ diff --git a/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene.json b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene.json index be7c93529c..b56e2124a1 100644 --- a/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene.json +++ b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene.json @@ -1741,7 +1741,7 @@ "Loop": true, "FileData": { "Type": "Normal", - "Path": "MP3/2.mp3" + "Path": "MP3/2.wav" }, "Tag": 35, "ObjectIndex": 1, diff --git a/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene_backup.json b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene_backup.json index a5d24f1997..461fee9872 100644 --- a/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene_backup.json +++ b/samples/js-tests/res/cocosui/UIEditorTest/2.1/res/MainScene_backup.json @@ -1741,7 +1741,7 @@ "Loop": true, "FileData": { "Type": "Normal", - "Path": "MP3/2.mp3" + "Path": "MP3/2.wav" }, "Tag": 35, "ObjectIndex": 1, 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/src/BillBoardTest/BillBoardTest.js b/samples/js-tests/src/BillBoardTest/BillBoardTest.js new file mode 100644 index 0000000000..595b628e14 --- /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 cc.Sprite3D(); + root.setNormalizedPosition(cc.p(0.5, 0.25)); + this.addChild(root); + + var model = new cc.Sprite3D("Sprite3DTest/orc.c3b"); + model.setScale(5); + model.setRotation3D(cc.math.vec3(0, 180, 0)); + root.addChild(model); + + var bill = new cc.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 cc.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 cc.BillBoard("Images/Icon.png"); + billboard1.setScale(0.2); + billboard1.setPosition3D(cc.math.vec3(0, 30, 0)); + + var billboard2 = new cc.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 cc.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 cc.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 cc.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(cc.BillBoard.Mode.VIEW_POINT_ORIENTED); + } + }, + + menuCallback_orientedPlane:function(sender){ + for(var i = 0; i < this._billboards.length; ++i){ + this._billboards[i].setMode(cc.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..1fa202594c --- /dev/null +++ b/samples/js-tests/src/Camera3DTest/Camera3DTest.js @@ -0,0 +1,1279 @@ +/**************************************************************************** + 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 cc.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 cc.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 cc.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 cc.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 cc.Sprite3D(file); + this._layer3D.addChild(sprite); + var globalZOrder = sprite.getGlobalZOrder(); + sprite.setPosition3D(postion); + sprite.setGlobalZOrder(globalZOrder); + if(playAnimation){ + var animation = cc.Animation3D.create(file, "Take 001"); + if(animation){ + var animate = cc.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); + + var size = cc.winSize; + nearP = this._camera.unproject(size, nearP); + farP = this._camera.unproject(size, 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.moveTo(4, cc.p(100, 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 cc.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 cc.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(size, src); + src = cc.math.vec3(0, 0, 1); + var tl_1 = this._cameraFirst.unproject(size, src); + + // top-right + src = cc.math.vec3(size.width, 0, 0); + var tr_0 = this._cameraFirst.unproject(size, src); + src = cc.math.vec3(size.width, 0, 1); + var tr_1 = this._cameraFirst.unproject(size, src); + + // bottom-left + src = cc.math.vec3(0, size.height, 0); + var bl_0 = this._cameraFirst.unproject(size, src); + src = cc.math.vec3(0, size.height, 1); + var bl_1 = this._cameraFirst.unproject(size, src); + + // bottom-right + src = cc.math.vec3(size.width, size.height, 0); + var br_0 = this._cameraFirst.unproject(size, src); + src = cc.math.vec3(size.width, size.height, 1); + var br_1 = this._cameraFirst.unproject(size, 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 cc.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 cc.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 cc.Sprite3D("Sprite3DTest/teapot.c3b"); + this._sprite3D2 = new cc.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){ + 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/CocosDenshionTest/CocosDenshionTest.js b/samples/js-tests/src/CocosDenshionTest/CocosDenshionTest.js index ad96d2a6c2..6296860447 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 ? "res/Sound/background-music-aac.wav" : "res/Sound/background.mp3"; +var EFFECT_FILE = cc.sys.os === cc.sys.OS_WP8 ? "res/Sound/pew-pew-lei.wav" : "res/Sound/effect2.mp3"; var _DenshionTests = [ 'Music Test' diff --git a/samples/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js b/samples/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js index e9f1a8afd2..05385870f7 100644 --- a/samples/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js +++ b/samples/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js @@ -30,6 +30,10 @@ var UIListViewTest_Vertical = UIScene.extend({ var background = this._widget.getChildByName("background_Panel"); var backgroundSize = background.getContentSize(); + this._topDisplayLabel.setString("Scroll listview is disabled."); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; + this._array = []; for (var i = 0; i < 20; ++i) { this._array.push("item_" + i); diff --git a/samples/js-tests/src/LabelTest/LabelTest.js b/samples/js-tests/src/LabelTest/LabelTest.js index 2dce12f356..33b37b53ee 100644 --- a/samples/js-tests/src/LabelTest/LabelTest.js +++ b/samples/js-tests/src/LabelTest/LabelTest.js @@ -1331,13 +1331,13 @@ var LabelTTFChinese = AtlasDemo.extend({ //----start21----ctor this._super(); var size = director.getWinSize(); - var label = new cc.LabelTTF("中国", "Microsoft Yahei", 30); + var label = new cc.LabelTTF("中国", (cc.sys.os == cc.sys.OS_WP8) ? "fonts/arialuni.ttf" : "Microsoft Yahei", 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(), (cc.sys.os == cc.sys.OS_WP8) ? "fonts/arialuni.ttf" : "Microsoft Yahei", 30); label2.x = size.width / 2; label2.y = size.height / 3; this.addChild(label2); @@ -1941,6 +1941,8 @@ 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"); self.addChild(LabelTTF); }); @@ -1963,6 +1965,8 @@ 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"); self.addChild(LabelTTF); }); @@ -1981,6 +1985,8 @@ 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"); 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..2410ce8608 --- /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 cc.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 cc.Sprite3D("Sprite3DTest/axe.c3b"); + orc.getAttachNode("Bip001 R Hand").addChild(axe); + var animation = cc.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = cc.Animate3D.create(animation); + orc.runAction(cc.repeatForever(animate)); + } + this.addChild(orc); + orc.setCameraMask(2); + + var sphere1 = new cc.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere1.setPosition(cc.p(30, 0)); + this.addChild(sphere1); + sphere1.setCameraMask(2); + + var sphere2 = new cc.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere2.setPosition(cc.p(-50, 0)); + sphere2.setScale(0.5); + this.addChild(sphere2); + sphere2.setCameraMask(2); + + var sphere3 = new cc.Sprite3D("Sprite3DTest/sphere.c3b"); + sphere3.setPosition(cc.p(-30, 0)); + sphere3.setScale(0.5); + this.addChild(sphere3); + sphere3.setCameraMask(2); + }, + + addLights:function(){ + this._ambientLight = cc.AmbientLight.create(cc.color(200, 200, 200)); + this._ambientLight.setEnabled(true); + this.addChild(this._ambientLight); + this._ambientLight.setCameraMask(2); + + this._directionalLight = cc.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 = cc.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 = cc.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/Sprite3DTest/Sprite3DTest.js b/samples/js-tests/src/Sprite3DTest/Sprite3DTest.js new file mode 100644 index 0000000000..6a725f972b --- /dev/null +++ b/samples/js-tests/src/Sprite3DTest/Sprite3DTest.js @@ -0,0 +1,1591 @@ +/**************************************************************************** + 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 cc.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 cc.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 cc.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 + cc.Sprite3DCache.getInstance().removeAllSprite3DData(); + + for(var i = 0; i < this._path.length; ++i){ + cc.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 cc.Sprite3D("Sprite3DTest/orc.c3b"); + sprite.setScale(3); + sprite.setRotation3D({x : 0, y : 180, z: 0}); + this.addChild(sprite); + sprite.setPosition(position); + + var animation = cc.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = cc.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 cc.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 = cc.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = cc.Animate3D.create(animation, 0, 1.933); + this._swim = new cc.RepeatForever(animate); + sprite.runAction(this._swim); + + this._swim.retain(); + this._hurt = cc.Animate3D.create(animation, 1.933, 2.8); + this._hurt.retain(); + + this._state = State.SWIMMING; + } + + this._moveAction = cc.moveTo(4.0, cc.p(s.width / 5, s.height / 2)); + 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() - cc.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 >= cc.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 >= cc.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 cc.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 cc.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = cc.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = cc.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 cc.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 cc.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 = cc.Animation3D.create("Sprite3DTest/ReskinGirl.c3b"); + if(animation){ + var animate = cc.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 cc.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 = cc.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = cc.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + this._moveAction = cc.moveTo(4, cc.p(s.width / 5, s.height / 2)); + 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 size = cc.winSize; + + var src = cc.math.vec3(location.x, location.y, -1); + var nearPoint = camera.unproject(size, src); + + src = cc.math.vec3(location.x, location.y, 1); + var farPoint = camera.unproject(size, 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 cc.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 cc.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = cc.Animation3D.create(fileName); + if(animation){ + var animate = cc.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + //create mirror Sprite3D + sprite = new cc.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 cc.Sprite3D("Sprite3DTest/axe.c3b"); + sprite.getAttachNode("Bip001 R Hand").addChild(sp); + + var animation = cc.Animation3D.create(fileName); + if(animation){ + var animate = cc.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 cc.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 = cc.Animation3D.create("Sprite3DTest/tortoise.c3b"); + if(animation){ + var animate = cc.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 cc.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 cc.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 cc.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 cc.Sprite3D("Sprite3DTest/girl.c3b"); + sprite.setScale(0.15); + var animation = cc.Animation3D.create("Sprite3DTest/girl.c3b"); + if(animation){ + var animate = cc.Animate3D.create(animation); + sprite.runAction(cc.repeatForever(animate)); + } + + var circleBack = new cc.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 cc.Sprite3D("Sprite3DTest/girl.c3b"); + sprite.setScale(0.5); + var animation = cc.Animation3D.create("Sprite3DTest/girl.c3b"); + if(animation){ + var animate = cc.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 = cc.Animation3D.create("Sprite3DTest/orc.c3b"); + if(animation){ + var animate = cc.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 cc.Sprite3D("Sprite3DTest/LightMapScene.c3b"); + LightMapScene.setScale(0.1); + this.addChild(LightMapScene); + this.addChild(this._camera); + this.setCameraMask(2); + + //add a point light + var light = cc.PointLight.create(cc.math.vec3(35, 75, -20.5), cc.color(255, 255, 255), 150); + this.addChild(light); + //set the ambient light + var ambient = cc.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 cc.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 cc.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 cc.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); + + var size = cc.winSize; + nearP = this._camera.unproject(size, nearP); + farP = this._camera.unproject(size, 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 cc.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){ + 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/TextureCacheTest/TextureCacheTest.js b/samples/js-tests/src/TextureCacheTest/TextureCacheTest.js index 760130fed8..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(); @@ -205,7 +205,7 @@ var RemoteTextureTest = TextureCacheTestBase.extend({ }, 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/XHRTest.js b/samples/js-tests/src/XHRTest/XHRTest.js index 5712c2b541..47ce4b5cae 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) { diff --git a/samples/js-tests/src/tests-main.js b/samples/js-tests/src/tests-main.js index 063001287a..8519d91dc7 100644 --- a/samples/js-tests/src/tests-main.js +++ b/samples/js-tests/src/tests-main.js @@ -243,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, @@ -252,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, @@ -414,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, @@ -548,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, diff --git a/templates/js-template-default/cocos-project-template.json b/templates/js-template-default/cocos-project-template.json index 8269feb651..92bc130708 100644 --- a/templates/js-template-default/cocos-project-template.json +++ b/templates/js-template-default/cocos-project-template.json @@ -68,7 +68,11 @@ "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" ] }, "project_replace_project_name":{ @@ -80,6 +84,9 @@ "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", 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..441f27735a 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,8 @@ #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 "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 +50,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) + 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 +66,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 +99,10 @@ 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); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(JavascriptJavaBridge::_js_register); @@ -103,8 +112,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.win32/HelloJavascript.vcxproj b/templates/js-template-default/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj index 28c323f929..78d627ccca 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,11 +102,11 @@ 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 @@ -163,11 +163,11 @@ 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 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 @@ + + + + + + +