- Timestamp:
- 07/17/11 01:24:14 (13 years ago)
- Location:
- ps/trunk
- Files:
-
- 1 added
- 27 edited
-
build/premake/extern_libs.lua (modified) (1 diff)
-
build/premake/extern_libs4.lua (modified) (1 diff)
-
build/workspaces/update-workspaces-new.sh (modified) (1 diff)
-
build/workspaces/update-workspaces.sh (modified) (1 diff)
-
source/gui/CGUI.cpp (modified) (2 diffs)
-
source/gui/IGUIObject.h (modified) (1 diff)
-
source/gui/scripting/JSInterface_GUITypes.cpp (modified) (3 diffs)
-
source/gui/scripting/JSInterface_IGUIObject.cpp (modified) (1 diff)
-
source/gui/scripting/JSInterface_IGUIObject.h (modified) (1 diff)
-
source/maths/scripting/JSInterface_Vector3D.cpp (modified) (1 diff)
-
source/maths/scripting/JSInterface_Vector3D.h (modified) (1 diff)
-
source/ps/ConfigDB.cpp (modified) (2 diffs)
-
source/ps/scripting/JSInterface_Console.cpp (modified) (1 diff)
-
source/ps/scripting/JSInterface_Console.h (modified) (1 diff)
-
source/scripting/ScriptableObject.h (modified) (1 diff)
-
source/scripting/ScriptingHost.cpp (modified) (1 diff)
-
source/scriptinterface/NativeWrapperDefns.h (modified) (1 diff)
-
source/scriptinterface/ScriptConversions.cpp (modified) (2 diffs)
-
source/scriptinterface/ScriptExtraHeaders.h (added)
-
source/scriptinterface/ScriptInterface.cpp (modified) (16 diffs)
-
source/scriptinterface/ScriptTypes.h (modified) (2 diffs)
-
source/simulation2/components/CCmpAIManager.cpp (modified) (2 diffs)
-
source/simulation2/scripting/EngineScriptConversions.cpp (modified) (2 diffs)
-
source/simulation2/serialization/BinarySerializer.cpp (modified) (2 diffs)
-
source/simulation2/system/InterfaceScripted.h (modified) (1 diff)
-
source/tools/atlas/AtlasObject/AtlasObjectJS.cpp (modified) (2 diffs)
-
source/tools/atlas/AtlasScript/ScriptInterface.cpp (modified) (7 diffs)
-
source/tools/atlas/AtlasScript/ScriptInterface.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/build/premake/extern_libs.lua
r9574 r9852 191 191 include_dir = "include-unix" 192 192 end 193 tinsert(package.config["Debug" ].includepaths, libraries_dir.."spidermonkey -tip/"..include_dir.."/debug")194 tinsert(package.config["Testing"].includepaths, libraries_dir.."spidermonkey -tip/"..include_dir.."/debug")195 tinsert(package.config["Release"].includepaths, libraries_dir.."spidermonkey -tip/"..include_dir.."/release")196 tinsert(package.libpaths, libraries_dir.."spidermonkey -tip/lib")197 tinsert(package.config["Debug" ].links, "mozjs -ps-debug")198 tinsert(package.config["Testing"].links, "mozjs -ps-release")199 tinsert(package.config["Release"].links, "mozjs -ps-release")193 tinsert(package.config["Debug" ].includepaths, libraries_dir.."spidermonkey/"..include_dir) 194 tinsert(package.config["Testing"].includepaths, libraries_dir.."spidermonkey/"..include_dir) 195 tinsert(package.config["Release"].includepaths, libraries_dir.."spidermonkey/"..include_dir) 196 tinsert(package.libpaths, libraries_dir.."spidermonkey/lib") 197 tinsert(package.config["Debug" ].links, "mozjs185-ps-debug") 198 tinsert(package.config["Testing"].links, "mozjs185-ps-release") 199 tinsert(package.config["Release"].links, "mozjs185-ps-release") 200 200 end, 201 201 }, -
ps/trunk/build/premake/extern_libs4.lua
r9830 r9852 486 486 end 487 487 configuration "Debug" 488 includedirs { libraries_dir.."spidermonkey -tip/"..include_dir.."/debug"}488 includedirs { libraries_dir.."spidermonkey/"..include_dir } 489 489 configuration "Testing" 490 includedirs { libraries_dir.."spidermonkey -tip/"..include_dir.."/debug"}490 includedirs { libraries_dir.."spidermonkey/"..include_dir } 491 491 configuration "Release" 492 includedirs { libraries_dir.."spidermonkey -tip/"..include_dir.."/release"}492 includedirs { libraries_dir.."spidermonkey/"..include_dir } 493 493 configuration { } 494 494 end, 495 495 link_settings = function() 496 496 configuration "Debug" 497 links { "mozjs -ps-debug" }497 links { "mozjs185-ps-debug" } 498 498 configuration "Testing" 499 links { "mozjs -ps-debug" }499 links { "mozjs185-ps-debug" } 500 500 configuration "Release" 501 links { "mozjs -ps-release" }501 links { "mozjs185-ps-release" } 502 502 configuration { } 503 add_default_lib_paths("spidermonkey -tip")503 add_default_lib_paths("spidermonkey") 504 504 end, 505 505 }, -
ps/trunk/build/workspaces/update-workspaces-new.sh
r9830 r9852 51 51 (cd ../../libraries/fcollada/src && make ${JOBS}) || die "FCollada build failed" 52 52 echo 53 (cd ../../libraries/spidermonkey -tip&& JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"53 (cd ../../libraries/spidermonkey && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed" 54 54 echo 55 55 if [ "$with_system_nvtt" = "false" ]; then -
ps/trunk/build/workspaces/update-workspaces.sh
r9766 r9852 50 50 (cd ../../libraries/fcollada/src && make ${JOBS}) || die "FCollada build failed" 51 51 echo 52 (cd ../../libraries/spidermonkey -tip&& JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"52 (cd ../../libraries/spidermonkey && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed" 53 53 echo 54 54 if [ "$with_system_nvtt" = "false" ]; then -
ps/trunk/source/gui/CGUI.cpp
r9362 r9852 326 326 } 327 327 328 static JSBool SetGlobalProperty(JSContext* cx, JSObject* UNUSED(obj), jsid id, jsval* vp)328 static JSBool SetGlobalProperty(JSContext* cx, JSObject* UNUSED(obj), jsid id, JSBool UNUSED(strict), jsval* vp) 329 329 { 330 330 return JS_SetPropertyById(cx, g_ScriptingHost.GetGlobalObject(), id, vp); … … 377 377 static JSClass page_global_class = { 378 378 "page_global", JSCLASS_GLOBAL_FLAGS | JSCLASS_NEW_RESOLVE, 379 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_ PropertyStub,379 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 380 380 JS_EnumerateStub, (JSResolveOp)ResolveGlobalProperty, JS_ConvertStub, JS_FinalizeStub, 381 381 NULL, NULL, NULL, NULL, -
ps/trunk/source/gui/IGUIObject.h
r9340 r9852 147 147 // Allow getProperty to access things like GetParent() 148 148 friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp); 149 friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);149 friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp); 150 150 151 151 public: -
ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp
r8929 r9852 25 25 "GUISize", 0, 26 26 JS_PropertyStub, JS_PropertyStub, 27 JS_PropertyStub, JS_ PropertyStub,27 JS_PropertyStub, JS_StrictPropertyStub, 28 28 JS_EnumerateStub, JS_ResolveStub, 29 29 JS_ConvertStub, JS_FinalizeStub, … … 138 138 "GUIColor", 0, 139 139 JS_PropertyStub, JS_PropertyStub, 140 JS_PropertyStub, JS_ PropertyStub,140 JS_PropertyStub, JS_StrictPropertyStub, 141 141 JS_EnumerateStub, JS_ResolveStub, 142 142 JS_ConvertStub, JS_FinalizeStub, … … 215 215 "GUIMouse", 0, 216 216 JS_PropertyStub, JS_PropertyStub, 217 JS_PropertyStub, JS_ PropertyStub,217 JS_PropertyStub, JS_StrictPropertyStub, 218 218 JS_EnumerateStub, JS_ResolveStub, 219 219 JS_ConvertStub, JS_FinalizeStub, -
ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp
r9423 r9852 291 291 } 292 292 293 JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)293 JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp) 294 294 { 295 295 IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); -
ps/trunk/source/gui/scripting/JSInterface_IGUIObject.h
r8629 r9852 27 27 extern JSFunctionSpec JSI_methods[]; 28 28 JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp); 29 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);29 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp); 30 30 JSBool construct(JSContext* cx, uintN argc, jsval* vp); 31 31 JSBool toString(JSContext* cx, uintN argc, jsval* vp); -
ps/trunk/source/maths/scripting/JSInterface_Vector3D.cpp
r8629 r9852 126 126 } 127 127 128 JSBool JSI_Vector3D::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)128 JSBool JSI_Vector3D::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp) 129 129 { 130 130 if (!JSID_IS_INT(id)) -
ps/trunk/source/maths/scripting/JSInterface_Vector3D.h
r8629 r9852 58 58 59 59 JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp); 60 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);60 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp); 61 61 void finalize(JSContext* cx, JSObject* obj); 62 62 JSBool construct(JSContext* cx, uintN argc, jsval* vp); -
ps/trunk/source/ps/ConfigDB.cpp
r9410 r9852 61 61 } 62 62 63 JSBool SetProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)63 JSBool SetProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp) 64 64 { 65 65 EConfigNamespace cfgNs = GET_NS_PRIVATE(cx, obj); … … 170 170 "ConfigDB", 0, 171 171 JS_PropertyStub, JS_PropertyStub, 172 JS_PropertyStub, JS_ PropertyStub,172 JS_PropertyStub, JS_StrictPropertyStub, 173 173 JS_EnumerateStub, JS_ResolveStub, 174 174 JS_ConvertStub, JS_FinalizeStub -
ps/trunk/source/ps/scripting/JSInterface_Console.cpp
r8629 r9852 63 63 } 64 64 65 JSBool JSI_Console::setProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, jsval* vp)65 JSBool JSI_Console::setProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, JSBool UNUSED(strict), jsval* vp) 66 66 { 67 67 if (!JSID_IS_INT(id)) -
ps/trunk/source/ps/scripting/JSInterface_Console.h
r8629 r9852 36 36 37 37 JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp); 38 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);38 JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp); 39 39 40 40 JSBool getConsole(JSContext* context, JSObject* obj, jsid id, jsval* vp); -
ps/trunk/source/scripting/ScriptableObject.h
r9362 r9852 408 408 return( JS_TRUE ); 409 409 } 410 static JSBool JSSetProperty( JSContext* cx, JSObject* obj, jsid id, jsval* vp )410 static JSBool JSSetProperty( JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp ) 411 411 { 412 412 T* Instance = ToNative<T>( cx, obj ); -
ps/trunk/source/scripting/ScriptingHost.cpp
r9107 r9852 209 209 throw PSERROR_Scripting_ConversionFailed(); 210 210 211 jschar *strptr=JS_GetStringChars(string); 212 size_t length=JS_GetStringLength(string); 211 size_t length; 212 const jschar *strptr = JS_GetStringCharsAndLength(m_Context, string, &length); 213 if (!strptr) 214 throw PSERROR_Scripting_ConversionFailed(); 215 213 216 return std::wstring(strptr, strptr+length); 214 217 } -
ps/trunk/source/scriptinterface/NativeWrapperDefns.h
r9362 r9852 73 73 74 74 // Fast natives don't trigger the hook we use for profiling, so explicitly 75 // notify the profiler when these functions are being called 75 // notify the profiler when these functions are being called. 76 // ScriptInterface_impl::Register stores the name in a reserved slot. 77 // (TODO: this doesn't work for functions registered via InterfaceScripted.h. 78 // Maybe we should do some interned JS_GetFunctionId thing.) 76 79 #if ENABLE_SCRIPT_PROFILING 77 80 #define SCRIPT_PROFILE \ 78 81 ENSURE(JSVAL_IS_OBJECT(JS_CALLEE(cx, vp)) && JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)))); \ 79 const char* name = JS_GetFunctionName(JS_ValueToFunction(cx, JS_CALLEE(cx, vp))); /* native function so ValueToFunction is safe; this makes unsafe lifetime assumptions */ \ 82 const char* name = "(unknown)"; \ 83 jsval nameval; \ 84 if (JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0, &nameval) \ 85 && !JSVAL_IS_VOID(nameval)) \ 86 name = static_cast<const char*>(JSVAL_TO_PRIVATE(nameval)); \ 80 87 CProfileSampleScript profile(name); 81 88 #else -
ps/trunk/source/scriptinterface/ScriptConversions.cpp
r9664 r9852 24 24 #include "ps/CLogger.h" 25 25 #include "ps/CStr.h" 26 27 #include "js/jsapi.h" 28 29 #define signbit std::signbit 30 #include "js/jstypedarray.h" 31 #undef signbit 26 #include "scriptinterface/ScriptExtraHeaders.h" // for typed arrays 32 27 33 28 #define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) … … 115 110 if (!ret) 116 111 FAIL("Argument must be convertible to a string"); 117 jschar* ch = JS_GetStringChars(ret); 118 out = std::wstring(ch, ch + JS_GetStringLength(ret)); 112 size_t length; 113 const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &length); 114 if (!ch) 115 FAIL("JS_GetStringsCharsAndLength failed"); // out of memory 116 out = std::wstring(ch, ch + length); 119 117 return true; 120 118 } -
ps/trunk/source/scriptinterface/ScriptInterface.cpp
r9699 r9852 46 46 #define STACK_CHUNK_SIZE 8192 47 47 48 #if ENABLE_SCRIPT_PROFILING 49 # define signbit std::signbit 50 # include "js/jsdbgapi.h" 51 # undef signbit 52 #endif 48 #include "scriptinterface/ScriptExtraHeaders.h" 53 49 54 50 //////////////////////////////////////////////////////////////// … … 58 54 public: 59 55 ScriptRuntime(int runtimeSize) : 60 m_rooter(NULL) 56 m_rooter(NULL), m_compartmentGlobal(NULL) 61 57 { 62 58 m_rt = JS_NewRuntime(runtimeSize); … … 85 81 JSRuntime* m_rt; 86 82 AutoGCRooter* m_rooter; 83 84 JSObject* m_compartmentGlobal; 87 85 88 86 private: … … 228 226 JSObject* m_glob; // global scope object 229 227 JSObject* m_nativeScope; // native function scope object 228 JSCrossCompartmentCall* m_call; 230 229 }; 231 230 … … 235 234 JSClass global_class = { 236 235 "global", JSCLASS_GLOBAL_FLAGS, 237 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_ PropertyStub,236 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 238 237 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, 239 238 NULL, NULL, NULL, NULL, … … 266 265 // TODO: this violates the docs ("The error reporter callback must not reenter the JSAPI.") 267 266 267 // Hide the exception from EvaluateScript 268 JSExceptionState* excnState = JS_SaveExceptionState(cx); 269 JS_ClearPendingException(cx); 270 268 271 jsval rval; 269 272 const char dumpStack[] = "this.stack.trimRight().replace(/^/mg, ' ')"; // indent each line … … 273 276 if (ScriptInterface::FromJSVal(cx, rval, stackTrace)) 274 277 msg << "\n" << stackTrace; 278 279 JS_RestoreExceptionState(cx, excnState); 280 } 281 else 282 { 283 // Error got replaced by new exception from EvaluateScript 284 JS_DropExceptionState(cx, excnState); 275 285 } 276 286 } … … 358 368 359 369 jsval ret; 360 if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret)) 370 371 // We'd usually do: 372 // if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret, NULL, NULL)) 373 // return JS_FALSE; 374 // but that function is broken in the 1.8.5 release 375 // (https://bugzilla.mozilla.org/show_bug.cgi?id=651510) 376 // so do an equivalent operation with a different API: 377 JSAutoStructuredCloneBuffer buf; 378 if (!buf.write(cx, JS_ARGV(cx, vp)[0]) || !buf.read(&ret, cx)) 361 379 return JS_FALSE; 362 380 … … 464 482 JS_BeginRequest(m_cx); 465 483 466 m_glob = JS_NewGlobalObject(m_cx, &global_class); 484 // We only want a single compartment per runtime 485 if (m_runtime->m_compartmentGlobal) 486 { 487 m_call = JS_EnterCrossCompartmentCall(m_cx, m_runtime->m_compartmentGlobal); 488 m_glob = JS_NewGlobalObject(m_cx, &global_class); 489 } 490 else 491 { 492 m_call = NULL; 493 m_glob = JS_NewCompartmentAndGlobalObject(m_cx, &global_class, NULL); 494 m_runtime->m_compartmentGlobal = m_glob; 495 } 496 467 497 ok = JS_InitStandardClasses(m_cx, m_glob); 468 498 ENSURE(ok); … … 486 516 ScriptInterface_impl::~ScriptInterface_impl() 487 517 { 518 if (m_call) 519 JS_LeaveCrossCompartmentCall(m_call); 488 520 JS_EndRequest(m_cx); 489 521 JS_DestroyContext(m_cx); … … 492 524 void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs) 493 525 { 494 JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); 526 JSFunction* func = JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); 527 528 if (!func) 529 return; 530 531 #if ENABLE_SCRIPT_PROFILING 532 // Store the function name in a slot, so we can pass it to the profiler. 533 534 // Use a flyweight std::string because we can't assume the caller has 535 // a correctly-aligned string and that its lifetime is long enough 536 typedef boost::flyweight< 537 std::string, 538 boost::flyweights::no_tracking 539 // can't use no_locking; Register might be called in threads 540 > LockedStringFlyweight; 541 542 LockedStringFlyweight fw(name); 543 JS_SetReservedSlot(m_cx, JS_GetFunctionObject(func), 0, PRIVATE_TO_JSVAL((void*)fw.get().c_str())); 544 #endif 495 545 } 496 546 … … 763 813 764 814 JSString* name = JSVAL_TO_STRING(val); 765 size_t len = JS_GetStringLength(name);766 jschar* chars = JS_GetStringChars(name);767 if ( len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0)815 size_t len; 816 const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len); 817 if (chars && len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0) 768 818 out.push_back(std::string(chars, chars+len)); // handles Unicode poorly 769 819 } … … 1103 1153 if (JSVAL_IS_STRING(val)) 1104 1154 { 1105 JSString* str = JS_NewUCStringCopyN(cxTo, JS_GetStringChars(JSVAL_TO_STRING(val)), JS_GetStringLength(JSVAL_TO_STRING(val))); 1155 size_t len; 1156 const jschar* chars = JS_GetStringCharsAndLength(cxFrom, JSVAL_TO_STRING(val), &len); 1157 CLONE_REQUIRE(chars, L"JS_GetStringCharsAndLength"); 1158 JSString* str = JS_NewUCStringCopyN(cxTo, chars, len); 1106 1159 CLONE_REQUIRE(str, L"JS_NewUCStringCopyN"); 1107 1160 jsval rval = STRING_TO_JSVAL(str); … … 1154 1207 JSString* idstr = JS_ValueToString(cxFrom, idval); 1155 1208 CLONE_REQUIRE(idstr, L"JS_ValueToString (id)"); 1156 CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, JS_GetStringChars(idstr), JS_GetStringLength(idstr), &newPropval), L"JS_SetUCProperty"); 1209 size_t len; 1210 const jschar* chars = JS_GetStringCharsAndLength(cxFrom, idstr, &len); 1211 CLONE_REQUIRE(idstr, L"JS_GetStringCharsAndLength (id)"); 1212 CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, chars, len, &newPropval), L"JS_SetUCProperty"); 1157 1213 } 1158 1214 else … … 1196 1252 uint64* data = NULL; 1197 1253 size_t nbytes = 0; 1198 if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes ))1254 if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes, NULL, NULL)) 1199 1255 return shared_ptr<StructuredClone>(); 1200 1256 // TODO: should we have better error handling? … … 1211 1267 { 1212 1268 jsval ret = JSVAL_VOID; 1213 JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, &ret);1269 JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, &ret, NULL, NULL); 1214 1270 return ret; 1215 1271 } -
ps/trunk/source/scriptinterface/ScriptTypes.h
r9827 r9852 1 /* Copyright (C) 201 0Wildfire Games.1 /* Copyright (C) 2011 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 48 48 #endif 49 49 50 // Ignore some harmless warnings triggered by jsapi.h 51 #if GCC_VERSION >= 402 // (older GCCs don't support this pragma) 52 # pragma GCC diagnostic ignored "-Wunused-parameter" 53 # pragma GCC diagnostic ignored "-Wredundant-decls" 54 #endif 55 #if MSC_VERSION 56 # pragma warning(push) 57 # pragma warning(disable:4480) // "nonstandard extension used: specifying underlying type for enum" 58 # pragma warning(disable:4100) // "unreferenced formal parameter" 59 #endif 60 50 61 #include "js/jsapi.h" 62 63 #if MSC_VERSION 64 # pragma warning(pop) 65 #endif 66 #if GCC_VERSION >= 402 67 # pragma GCC diagnostic warning "-Wunused-parameter" 68 # pragma GCC diagnostic warning "-Wredundant-decls" 69 #endif 51 70 52 71 #if JS_VERSION != 185 -
ps/trunk/source/simulation2/components/CCmpAIManager.cpp
r9720 r9852 91 91 // Clean up rooted objects before destroying their script context 92 92 m_Obj = CScriptValRooted(); 93 m_Commands.clear(); 93 94 } 94 95 … … 271 272 m_PlayerMetadata.clear(); 272 273 m_Players.clear(); 274 m_GameState.reset(); 275 m_GameStateMapVal = CScriptValRooted(); 273 276 } 274 277 -
ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp
r9362 r9852 19 19 20 20 #include "scriptinterface/ScriptInterface.h" 21 #include "scriptinterface/ScriptExtraHeaders.h" // for typed arrays 21 22 22 23 #include "maths/Fixed.h" … … 29 30 #include "simulation2/system/IComponent.h" 30 31 #include "simulation2/system/ParamNode.h" 31 32 #include "js/jsapi.h"33 34 #define signbit std::signbit35 #include "js/jstypedarray.h"36 #undef signbit37 32 38 33 #define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) -
ps/trunk/source/simulation2/serialization/BinarySerializer.cpp
r9363 r9852 26 26 27 27 #include "scriptinterface/ScriptInterface.h" 28 29 #define signbit std::signbit 30 #include "js/jsvalue.h" // for JSDOUBLE_IS_INT32 31 #undef signbit 28 #include "scriptinterface/ScriptExtraHeaders.h" // for JSDOUBLE_IS_INT32 32 29 33 30 CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer) : … … 189 186 void CBinarySerializerScriptImpl::ScriptString(const char* name, JSString* string) 190 187 { 191 jschar* chars = JS_GetStringChars(string); 192 size_t length = JS_GetStringLength(string); 188 JSContext* cx = m_ScriptInterface.GetContext(); 189 size_t length; 190 const jschar* chars = JS_GetStringCharsAndLength(cx, string, &length); 191 192 if (!chars) 193 throw PSERROR_Serialize_ScriptError("JS_GetStringCharsAndLength failed"); 193 194 194 195 #if BYTE_ORDER != LITTLE_ENDIAN -
ps/trunk/source/simulation2/system/InterfaceScripted.h
r8629 r9852 25 25 JSClass class_ICmp##iname = { \ 26 26 "ICmp" #iname, JSCLASS_HAS_PRIVATE, \ 27 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_ PropertyStub, \27 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \ 28 28 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, \ 29 29 JSCLASS_NO_OPTIONAL_MEMBERS \ -
ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectJS.cpp
r9566 r9852 72 72 return obj; // error 73 73 size_t valueLen; 74 const jschar* valueChars = JS_GetStringCharsAndLength( str, &valueLen);74 const jschar* valueChars = JS_GetStringCharsAndLength(cx, str, &valueLen); 75 75 if (!valueChars) 76 76 return obj; // error … … 112 112 113 113 JSString* name = JSVAL_TO_STRING(val); 114 size_t len = JS_GetStringLength(name);115 jschar* chars = JS_GetStringChars(name);116 wxString nameWx(reinterpret_cast<c har*>(chars), wxMBConvUTF16(), len*2);114 size_t len; 115 const jschar* chars = JS_GetStringCharsAndLength(cx, name, &len); 116 wxString nameWx(reinterpret_cast<const char*>(chars), wxMBConvUTF16(), len*2); 117 117 std::string nameStr(nameWx.ToUTF8().data()); 118 118 -
ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.cpp
r9827 r9852 24 24 #endif 25 25 26 #include "js/jsapi.h"27 28 #ifdef _WIN3229 # pragma warning(disable: 4996) // avoid complaints about deprecated localtime30 #endif31 32 26 #include "wx/wx.h" 33 27 … … 144 138 if (! ret) 145 139 FAIL("Argument must be convertible to a string"); 146 jschar* ch = JS_GetStringChars(ret); 147 out = std::wstring(ch, ch+JS_GetStringLength(ret)); 140 size_t len; 141 const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &len); 142 if (! ch) 143 FAIL("JS_GetStringsCharsAndLength failed"); // probably out of memory 144 out = std::wstring(ch, ch + len); 148 145 return true; 149 146 } … … 157 154 if (! ret) 158 155 FAIL("Argument must be convertible to a string"); 156 size_t len = JS_GetStringEncodingLength(cx, ret); 157 if (len == (size_t)-1) 158 FAIL("JS_GetStringEncodingLength failed"); 159 159 char* ch = JS_EncodeString(cx, ret); // chops off high byte of each jschar 160 160 if (! ch) 161 FAIL("JS_EncodeString failed"); // out of memory162 out = std::string(ch, ch + JS_GetStringLength(ret));161 FAIL("JS_EncodeString failed"); // probably out of memory 162 out = std::string(ch, ch + len); 163 163 JS_free(cx, ch); 164 164 return true; … … 171 171 { 172 172 JSString* ret = JS_ValueToString(cx, v); 173 size_t len; 173 174 if (! ret) 174 175 FAIL("Argument must be convertible to a string"); 175 jschar* ch = JS_GetStringChars(ret); 176 out = wxString((const char*)ch, wxMBConvUTF16(), (size_t)(JS_GetStringLength(ret)*2)); 176 const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &len); 177 if (! ch) 178 FAIL("JS_GetStringsCharsAndLength failed"); // probably out of memory 179 out = wxString((const char*)ch, wxMBConvUTF16(), len*2); 177 180 return true; 178 181 } … … 372 375 JSClass global_class = { 373 376 "global", JSCLASS_GLOBAL_FLAGS, 374 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_ PropertyStub,377 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 375 378 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, 376 379 NULL, NULL, NULL, NULL, … … 417 420 JSString* code = JSVAL_TO_STRING(JS_ARGV(cx, vp)[1]); 418 421 422 size_t len; 423 const jschar* ch = JS_GetStringCharsAndLength(cx, code, &len); 424 if (!ch) 425 return JS_FALSE; 426 419 427 jsval rval = JSVAL_VOID; 420 428 if (!AtlasScriptInterface_impl::LoadScript(cx, 421 JS_GetStringChars(code), (uintN)JS_GetStringLength(code),429 ch, (uintN)len, 422 430 name.c_str(), &rval)) 423 431 return JS_FALSE; … … 466 474 JS_SetVersion(m_cx, JSVERSION_LATEST); 467 475 468 m_glob = JS_New GlobalObject(m_cx, &global_class);476 m_glob = JS_NewCompartmentAndGlobalObject(m_cx, &global_class, NULL); 469 477 JS_InitStandardClasses(m_cx, m_glob); 470 478 -
ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.h
r9567 r9852 32 32 #endif // (we don't support XP_OS2 or XP_BEOS) 33 33 34 #ifdef __GNUC__ 35 # define GCC_VERSION (__GNUC__*100 + __GNUC_MINOR__) 36 #else 37 # define GCC_VERSION 0 38 #endif 39 40 #ifdef _MSC_VER 41 # define MSC_VERSION _MSC_VER 42 #else 43 # define MSC_VERSION 0 44 #endif 45 46 // Ignore some harmless warnings triggered by jsapi.h 47 #if GCC_VERSION >= 402 // (older GCCs don't support this pragma) 48 # pragma GCC diagnostic ignored "-Wunused-parameter" 49 # pragma GCC diagnostic ignored "-Wredundant-decls" 50 #endif 51 #if MSC_VERSION 52 # pragma warning(push) 53 # pragma warning(disable:4480) // "nonstandard extension used: specifying underlying type for enum" 54 # pragma warning(disable:4100) // "unreferenced formal parameter" 55 #endif 56 34 57 #include "js/jsapi.h" 58 59 #if MSC_VERSION 60 # pragma warning(pop) 61 #endif 62 #if GCC_VERSION >= 402 63 # pragma GCC diagnostic warning "-Wunused-parameter" 64 # pragma GCC diagnostic warning "-Wredundant-decls" 65 #endif 35 66 36 67 class wxString;
Note:
See TracChangeset
for help on using the changeset viewer.
