Command.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Command.m
  3. // MG
  4. //
  5. // Created by Tim Debo on 5/23/14.
  6. //
  7. //
  8. #import "Command.h"
  9. #import <WebKit/WebKit.h>
  10. #import "WindowController.h"
  11. @implementation Command
  12. @synthesize webView, windowController;
  13. + (JSValue *)makeConstructor:(id)block inContext:(JSContext *)context {
  14. JSValue *fun = [context evaluateScript:@"(function () { return this.__construct.apply(this, arguments); });"];
  15. fun[@"prototype"][@"__construct"] = block;
  16. return fun;
  17. }
  18. + (JSValue *)constructor {
  19. return [self makeConstructor:^{ return [self new]; } inContext:JSContext.currentContext];
  20. }
  21. - (NSString*) exportName {
  22. return NSStringFromClass([self class]);
  23. }
  24. - (id) initWithWindowController:(WindowController *)aWindowController
  25. {
  26. self = [super init];
  27. if(self) {
  28. self.windowController = aWindowController;
  29. self.webView = aWindowController.webView;
  30. }
  31. return self;
  32. }
  33. - (id) initWithContext:(JSContext*)context {
  34. self = [super init];
  35. if (!self)
  36. return nil;
  37. jsContext = [context JSGlobalContextRef];
  38. JSGlobalContextRetain((JSGlobalContextRef)jsContext);
  39. return self;
  40. }
  41. - (void)dealloc
  42. {
  43. if (jsContext)
  44. JSGlobalContextRelease((JSGlobalContextRef)jsContext);
  45. }
  46. - (void) initializePlugin {}
  47. @end