@@ -393,14 +393,16 @@ void registerDefaultClasses(JSContext* cx, JS::HandleObject global) {
393
393
JS::RootedValue nsval (cx);
394
394
JS::RootedObject ns (cx);
395
395
JS_GetProperty (cx, global, " cc" , &nsval);
396
- if (nsval == JSVAL_VOID) {
397
- JS::RootedObject proto (cx);
398
- JS::RootedObject parent (cx);
399
- ns = JS_NewObject (cx, NULL , proto, parent );
396
+ // Not exist, create it
397
+ if (nsval == JSVAL_VOID)
398
+ {
399
+ ns. set ( JS_NewObject (cx, NULL , JS::NullPtr (), JS::NullPtr ()) );
400
400
nsval = OBJECT_TO_JSVAL (ns);
401
401
JS_SetProperty (cx, global, " cc" , nsval);
402
- } else {
403
- JS_ValueToObject (cx, nsval, &ns);
402
+ }
403
+ else
404
+ {
405
+ ns.set (nsval.toObjectOrNull ());
404
406
}
405
407
406
408
//
@@ -554,12 +556,12 @@ static JSSecurityCallbacks securityCallbacks = {
554
556
};
555
557
556
558
void ScriptingCore::createGlobalContext () {
557
- if (this -> _cx && this -> _rt ) {
558
- ScriptingCore::removeAllRoots (this -> _cx );
559
- JS_DestroyContext (this -> _cx );
560
- JS_DestroyRuntime (this -> _rt );
561
- this -> _cx = NULL ;
562
- this -> _rt = NULL ;
559
+ if (_cx && _rt) {
560
+ ScriptingCore::removeAllRoots (_cx);
561
+ JS_DestroyContext (_cx);
562
+ JS_DestroyRuntime (_rt);
563
+ _cx = NULL ;
564
+ _rt = NULL ;
563
565
}
564
566
565
567
// Start the engine. Added in SpiderMonkey v25
@@ -568,40 +570,46 @@ void ScriptingCore::createGlobalContext() {
568
570
569
571
// Removed from Spidermonkey 19.
570
572
// JS_SetCStringsAreUTF8();
571
- this -> _rt = JS_NewRuntime (8L * 1024L * 1024L );
573
+ _rt = JS_NewRuntime (8L * 1024L * 1024L );
572
574
JS_SetGCParameter (_rt, JSGC_MAX_BYTES, 0xffffffff );
573
575
574
576
JS_SetTrustedPrincipals (_rt, &shellTrustedPrincipals);
575
577
JS_SetSecurityCallbacks (_rt, &securityCallbacks);
576
578
JS_SetNativeStackQuota (_rt, JSB_MAX_STACK_QUOTA);
577
579
578
- this -> _cx = JS_NewContext (_rt, 8192 );
580
+ _cx = JS_NewContext (_rt, 8192 );
579
581
580
582
// Removed in Firefox v27
581
583
// JS_SetOptions(this->_cx, JSOPTION_TYPE_INFERENCE);
582
584
// Removed in Firefox v33
583
585
// JS::ContextOptionsRef(_cx).setTypeInference(true);
584
- // JS::ContextOptionsRef(_cx).setIon(true);
585
- // JS::ContextOptionsRef(_cx).setBaseline(true);
586
586
587
587
JS::RuntimeOptionsRef (_rt).setIon (true );
588
588
JS::RuntimeOptionsRef (_rt).setBaseline (true );
589
589
590
590
// JS_SetVersion(this->_cx, JSVERSION_LATEST);
591
591
592
- JS_SetErrorReporter (this -> _cx , ScriptingCore::reportError);
592
+ JS_SetErrorReporter (_cx, ScriptingCore::reportError);
593
593
#if defined(JS_GC_ZEAL) && defined(DEBUG)
594
594
// JS_SetGCZeal(this->_cx, 2, JS_DEFAULT_ZEAL_FREQ);
595
595
#endif
596
- this ->_global .construct (_cx);
597
- this ->_global .ref () = NewGlobalObject (_cx);
598
-
599
- JSAutoCompartment ac (_cx, _global.ref ().get ());
600
- js::SetDefaultObjectForContext (_cx, _global.ref ().get ());
596
+ #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
597
+ _global.emplace (_cx);
598
+ #else
599
+ _global.construct (_cx);
600
+ #endif
601
+ _global.ref () = NewGlobalObject (_cx);
602
+
603
+ JSAutoCompartment ac (_cx, _global.ref ());
604
+
605
+ #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
606
+ // Removed in Firefox v34
607
+ js::SetDefaultObjectForContext (_cx, _global.ref ());
608
+ #endif
601
609
602
610
for (std::vector<sc_register_sth>::iterator it = registrationList.begin (); it != registrationList.end (); it++) {
603
611
sc_register_sth callback = *it;
604
- callback (this -> _cx , JS::RootedObject ( this -> _cx , this -> _global .ref (). get () ));
612
+ callback (_cx, _global.ref ());
605
613
}
606
614
}
607
615
@@ -727,8 +735,7 @@ void ScriptingCore::cleanAllScript()
727
735
728
736
bool ScriptingCore::runScript (const char *path)
729
737
{
730
- JS::RootedObject global (_cx, _global.ref ().get ());
731
- return runScript (path, global, _cx);
738
+ return runScript (path, _global.ref (), _cx);
732
739
}
733
740
734
741
bool ScriptingCore::runScript (const char *path, JS::HandleObject global, JSContext* cx)
@@ -1747,13 +1754,20 @@ bool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
1747
1754
1748
1755
void ScriptingCore::enableDebugger (unsigned int port)
1749
1756
{
1757
+ #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
1758
+ if (_debugGlobal.isNothing ())
1759
+ #else
1750
1760
if (_debugGlobal.empty ())
1761
+ #endif
1751
1762
{
1752
1763
JSAutoCompartment ac0 (_cx, _global.ref ().get ());
1753
1764
1754
1765
JS_SetDebugMode (_cx, true );
1755
-
1766
+ #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
1767
+ _debugGlobal.emplace (_cx);
1768
+ #else
1756
1769
_debugGlobal.construct (_cx);
1770
+ #endif
1757
1771
_debugGlobal.ref () = NewGlobalObject (_cx, true );
1758
1772
// Adds the debugger object to root, otherwise it may be collected by GC.
1759
1773
// AddObjectRoot(_cx, &_debugGlobal); no need, it's persistent rooted now
@@ -1781,7 +1795,7 @@ void ScriptingCore::enableDebugger(unsigned int port)
1781
1795
// start bg thread
1782
1796
auto t = std::thread (&serverEntryPoint,port);
1783
1797
t.detach ();
1784
-
1798
+
1785
1799
Scheduler* scheduler = Director::getInstance ()->getScheduler ();
1786
1800
scheduler->scheduleUpdate (this ->_runLoop , 0 , false );
1787
1801
}
0 commit comments