summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxant <xant@xant.net>2013-09-26 18:04:19 (GMT)
committer xant <xant@xant.net>2013-09-26 18:04:19 (GMT)
commit6e08268419d0353e6b9fa938714749d6b5f6e2ea (patch)
tree1bac9445971aba40a86a30bc4916a3e8beb07ffe
parent99021ad8f5ba067dc886b47e674b19631f4244a2 (diff)
just some more accessors exposing more data to javascript
notably entities' labels and classnames and a global function to clear all the timers registered in the current global context
-rw-r--r--core/JMXEntity.mm5
-rw-r--r--core/JMXPin.mm3
-rw-r--r--core/JMXScript.h3
-rw-r--r--core/JMXScript.mm40
4 files changed, 38 insertions, 13 deletions
diff --git a/core/JMXEntity.mm b/core/JMXEntity.mm
index 07e7126..5a9a45c 100644
--- a/core/JMXEntity.mm
+++ b/core/JMXEntity.mm
@@ -820,8 +820,7 @@ static v8::Handle<Value> MapSet(Local<String> name, Local<Value> value, const Ac
v8::Locker lock;
HandleScope handleScope;
Local<Object> obj = Local<Object>::Cast(info.Holder()->GetHiddenValue(String::NewSymbol("map")));
- obj->Set(name, value);
- return Undefined();
+ return handleScope.Close(v8::Boolean::New(obj->Set(name, value)));
}
static v8::Handle<Value> MapGet(Local<String> name, const AccessorInfo &info)
@@ -850,6 +849,8 @@ static v8::Handle<Value> MapGet(Local<String> name, const AccessorInfo &info)
instanceTemplate->SetInternalFieldCount(1);
// Add accessors for each of the fields of the entity.
+ instanceTemplate->SetAccessor(String::NewSymbol("className"), GetStringProperty, SetStringProperty);
+ instanceTemplate->SetAccessor(String::NewSymbol("label"), GetStringProperty, SetStringProperty);
instanceTemplate->SetAccessor(String::NewSymbol("description"), GetStringProperty);
instanceTemplate->SetAccessor(String::NewSymbol("input"), InputPins);
instanceTemplate->SetAccessor(String::NewSymbol("output"), OutputPins);
diff --git a/core/JMXPin.mm b/core/JMXPin.mm
index 4f9f416..3e94985 100644
--- a/core/JMXPin.mm
+++ b/core/JMXPin.mm
@@ -769,7 +769,6 @@ static v8::Handle<Value>connect(const Arguments& args)
static v8::Handle<Value>disconnectAll(const Arguments& args)
{
//v8::Locker lock;
- BOOL ret = NO;
HandleScope handleScope;
JMXPin *pin = (JMXPin *)args.Holder()->GetPointerFromInternalField(0);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -778,7 +777,7 @@ static v8::Handle<Value>disconnectAll(const Arguments& args)
[pin disconnectAllPins];
}
[pool release];
- return Undefined();
+ return handleScope.Close(v8::Boolean::New(!pin.connected));
}
static v8::Handle<Value>disconnect(const Arguments& args)
diff --git a/core/JMXScript.h b/core/JMXScript.h
index 2e2bb01..bec893a 100644
--- a/core/JMXScript.h
+++ b/core/JMXScript.h
@@ -157,8 +157,9 @@
/*!
@method clearTimers
@abstract clear all timers registered to this JS context
+ @return YES if all timers have been cleared NO otherwise
*/
-- (void)clearTimers;
+- (BOOL)clearTimers;
/*!
@method addRunLoopTimer:
diff --git a/core/JMXScript.mm b/core/JMXScript.mm
index c9b005b..c8d67f1 100644
--- a/core/JMXScript.mm
+++ b/core/JMXScript.mm
@@ -123,7 +123,8 @@ static const char* ToCString(const v8::String::Utf8Value& value) {
}
static v8::Handle<Value> ExportPin(const Arguments& args) {
- if (args.Length() < 1) return Undefined();
+ if (args.Length() < 1)
+ return Undefined();
//v8::Locker lock;
HandleScope scope;
v8::Handle<Object> pinObj = args[0]->ToObject();
@@ -190,7 +191,8 @@ static void ReportException(v8::TryCatch* try_catch) {
}
static v8::Handle<Value> IsDir(const Arguments& args) {
- if (args.Length() < 1) return Undefined();
+ if (args.Length() < 1)
+ return Undefined();
//v8::Locker lock;
HandleScope scope;
v8::Handle<Value> arg = args[0];
@@ -209,7 +211,8 @@ static v8::Handle<Value> IsDir(const Arguments& args) {
}
static v8::Handle<Value> ListDir(const Arguments& args) {
- if (args.Length() < 1) return Undefined();
+ if (args.Length() < 1)
+ return Undefined();
//v8::Locker lock;
HandleScope scope;
v8::Handle<Value> arg = args[0];
@@ -243,7 +246,8 @@ static v8::Handle<Value> FRand(const Arguments& args) {
}
static v8::Handle<Value> Echo(const Arguments& args) {
- if (args.Length() < 1) return v8::Undefined();
+ if (args.Length() < 1)
+ return v8::Undefined();
//v8::Locker lock;
HandleScope scope;
id obj = nil;
@@ -260,7 +264,7 @@ static v8::Handle<Value> Echo(const Arguments& args) {
v8::Unlocker unlocker;
NSLog(@"%s", *value);
//}
- return v8::Undefined();
+ return scope.Close(v8::Boolean::New(YES));
}
static v8::Handle<Value> DumpDOM(const Arguments& args) {
@@ -300,7 +304,8 @@ static BOOL ExecJSCode(const char *code, uint32_t length, const char *name)
}
static v8::Handle<Value> Include(const Arguments& args) {
- if (args.Length() < 1) return v8::Undefined();
+ if (args.Length() < 1)
+ return v8::Undefined();
//v8::Locker lock;
HandleScope scope;
v8::Handle<Value> arg = args[0];
@@ -358,7 +363,7 @@ static v8::Handle<Value> Sleep(const Arguments& args)
v8::Unlocker unlocker;
[NSThread sleepForTimeInterval:args[0]->NumberValue()];
}
- return Undefined();
+ return handleScope.Close(v8::Boolean::New(YES));
}
//static v8::Handle<Value> Run(const Arguments& args)
@@ -554,6 +559,18 @@ static v8::Handle<Value> ClearTimeout(const Arguments& args)
return handleScope.Close(v8::Boolean::New(0));
}
+static v8::Handle<Value> ClearAllTimers(const Arguments& args)
+{
+ v8::Locker locker;
+ HandleScope handleScope;
+ Local<Context> context = v8::Context::GetCalling();
+ Local<Object> globalObject = context->Global();
+ v8::Local<v8::Object> obj = globalObject->Get(String::New("scriptEntity"))->ToObject();
+ JMXScriptEntity *entity = (JMXScriptEntity *)obj->GetPointerFromInternalField(0);
+ JMXScript *scriptContext = entity.jsContext;
+ return handleScope.Close(v8::Boolean::New([scriptContext clearTimers]));
+}
+
@interface JMXScript ()
{
NSThread *timersThread;
@@ -785,6 +802,9 @@ static Persistent<ObjectTemplate> ctxTemplate;
ctxTemplate->Set(String::New("setInterval"), FunctionTemplate::New(SetInterval));
ctxTemplate->Set(String::New("clearInterval"), FunctionTemplate::New(ClearTimeout)); // alias for ClearTimeout
+
+ ctxTemplate->Set(String::New("clearAllTimers"), FunctionTemplate::New(ClearAllTimers)); // alias for ClearAllTimers
+
#endif
ctxTemplate->SetInternalFieldCount(1);
@@ -897,14 +917,18 @@ static Persistent<ObjectTemplate> ctxTemplate;
[pool drain];
}
-- (void)clearTimers
+- (BOOL)clearTimers
{
+ BOOL ret = YES;
@synchronized(timersThread) {
for (JMXScriptTimer *t in runloopTimers) {
[t invalidate];
+ if (t.timer.isValid)
+ ret = NO;
}
[runloopTimers removeAllObjects];
}
+ return (ret && !runloopTimers.count);
//[self execCode:@"clearAllTimers()"];
}