JavaScriptCore

Similar documents

AirPrintPublic

Swift1.key

Microsoft Word - MDOnline 2001.

lifedesign_contest_No3

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

) CoreImage 2013/5/25 iphone

index View Controller


JavaScript の使い方

Swiftではじめる iPhoneアプリ開発の教科書 【iOS 8&Xcode 6対応】初版第2刷差分

Lecture 3 Slides (January 12, 2010)

Objective-C Objective-C C Toolbox API Cocoa Objective-C Java Carbon API C API Objective-C Java Pure Java Java AppleScript Java Objective-C Project Bui


StringProgrammingGuide

javascript key

Condition DAQ condition condition 2 3 XML key value

Microsoft Word - MDOnline 2001.

<4D F736F F D20694F538F5A91EE A20838A C >

program.dvi

cpp1.dvi

ジョインポイント写像に基づく ドメイン特化AO機構の開発手法

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

paper.pdf

NSDate NSCalendarDate NSObject NSDate NSCalendarDate NSDate NSCalendarDate NSDate NSCalendar NSDate date NSDate *d = [ NSDate date ]; // NSDate : + (i

Java演習(4) -- 変数と型 --

Microsoft Word - iPhone_finalv3.doc

A B 1: Ex. MPICH-G2 C.f. NXProxy [Tanaka] 2:

K227 Java 2

‚æ4›ñ

haskell.gby

Gartner Day

RHEA key

とても使いやすい Boost の serialization


ch31.dvi

P.1P.3 P.4P.7 P.8P.12 P.13P.25 P.26P.32 P.33


text_08.dvi

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

Parametric Polymorphism

2

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

untitled


JavaScript 1.! DOM Ajax Shelley Powers,, JavaScript David Flanagan, JavaScript 2

VB.NETコーディング標準

Java updated

) 2013/7/27 iphone

presen.gby

TextSystemOverview

cssnitelp47_hasegawa_v02.key

sp2-2.indd

2. 2 (LAN) Web 7 2 DBMS Java Applet 2.1 Java RDBMS Java 1 Lisp S S Common Lisp Java DBMS 2.2 DBMS RDBMS(Oracle) Java BLOB(Binary Large OBject) RDBMS R

WinHPC ppt

PowerPoint プレゼンテーション

1_cover

SmartBrowser_document_build30_update.pptx

BW BW


1.ppt

アルゴリズムとデータ構造1

SystemC言語概論

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

r07.dvi

h1,..., h6: (heading) h1 h2 table: table tr (table row) tr td (table data) ol, ul: (ordered) (unordered) </tag1> </tag4> 1: HTML [1] html: Web HTML he

ohp07.dvi

r08.dvi

exec.dvi

2

インターネットマガジン2001年9月号―INTERNET magazine No.80

r3.dvi

2017_08_ICN研究会_印刷用

Lecture 2 Slides (January 7, 2010)

Pascal Pascal Free Pascal CPad for Pascal Microsoft Windows OS Pascal

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse


Cプログラミング - 第8回 構造体と再帰

Smalltalk_

For_Beginners_CAPL.indd

MPI MPI MPI.NET C# MPI Version2

ex01.dvi

myx_backup Ver 1.10のPHP7対応

r03.dvi


Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

< F2D834F838C A815B A CC>

ALG ppt

jssst-ocaml.mgp

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

( )

WPD2009_Plone3_theme-2.key

Hasegawa_pacsec.pptx

Copyright c 2006 Zhenjiang Hu, All Right Reserved.

Quartz OpenGL ES 注 3 注 4 図 2 注 5 3 3D OpenGL ES Quartz Quartz Jun

monad.gby

スライド 1

WPF アプリケーションの 多言語切替

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

Transcription:

http://kishikawakatsumi.com Twitter @k_katsumi 24/7 twenty-four seven http://d.hatena.ne.jp/kishikawakatsumi/

JSContext *context = [[JSContext alloc] init]; JSValue *result = [context evaluatescript:@"2 + 8"]; NSLog(@"%d", result.toint32);

JSContext *context = [[JSContext alloc] init]; context[@"factorial"] = ^(int x) { int factorial = 1; for (; x > 1; x--) { factorial *= x; } return factorial; }; JSValue *result = [context evaluatescript:@"factorial(5);"]; NSLog(@"%d", result.toint32);

JSContext *context = [[JSContext alloc] init]; context[@"factorial"] = ^(int x) { int factorial = 1; for (; x > 1; x--) { factorial *= x; } return factorial; }; JSValue *function = context[@ factorial"]; JSValue *result = [function callwitharguments:@[@(5)]]; NSLog(@"%d", result.toint32);

JSContext *context = [[JSContext alloc] init]; [context evaluatescript: @"function sum(a, b) { return a + b; }" ]; JSValue *function = context[@ sum"]; JSValue *result = [function callwitharguments:@[@(2), @(3)]] NSLog(@"%d", result.toint32);

NSBundle *bundle = [NSBundle mainbundle]; NSString *path = [bundle pathforresource:@"text-hatena" oftype:@"js"]; NSString *script = [NSString stringwithcontentsoffile:path encoding:nsutf8stringencoding error:nil]; JSContext *context = [[JSContext alloc] init]; [context evaluatescript:script]; [context evaluatescript:@"var parser = new TextHatena();"]; JSValue *parser = context[@"parser"]; NSString *text = [NSString stringwithcontentsoffile: [bundle pathforresource:@ sample oftype:@ txt"] encoding:nsutf8stringencoding error:nil]; NSLog(@"%@", [parser invokemethod:@"parse" witharguments:@[text]]); return YES;

*1384756611*[Objective-C][iOS]iOS - [http://mobiletou.ch/2013/11/ ios%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a7%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%83%9c%e3 %83%BC%E3%83%89%E3%81%8B%E3%82%89%E3%81%AE%E3%82%B7%E3%83%A7%E3%83%BC%E3%83%88%E3%82%AB %E3%83%83%E3%83%88:title=iOS - ios ] ios 7Safari[http:// www.appbank.net/2013/11/08/iphone-news/696998.php:title= ] ios 7API > objc @property(nonatomic, readonly) NSArray *keycommands <

<div class="section"> <h3><a href="#1384756611" name="1384756611"><span class="sanchor">o-</span></a> [<a class="sectioncategory" href="searchdiary?word=*[objective-c]">objective-c</a>][<a class="sectioncategory" href="searchdiary?word=*[ios]">ios</a>]ios </h3> <p> </p> <ul> <li> [http://mobiletou.ch/2013/11/ ios%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a7%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%83%9c%e3%83%bc%e3%8 3%89%E3%81%8B%E3%82%89%E3%81%AE%E3%82%B7%E3%83%A7%E3%83%BC%E3%83%88%E3%82%AB%E3%83%83%E3%83%88:tit le=ios - ios]</li> </ul> <br> <p>ios 7Safari[http:// www.appbank.net/2013/11/08/iphone-news/696998.php:title=]</p> <br> <p>ios 7API </p> <br> <p></p> <pre class="syntax-highlight prettyprint lang-objc"> @property(nonatomic, readonly) NSArray *keycommands </pre>

NSBundle *bundle = [NSBundle mainbundle]; NSString *path = [bundle pathforresource:@"textile" oftype:@"js"]; NSString *script = [NSString stringwithcontentsoffile:path encoding:nsutf8stringencoding error:nil]; JSContext *context = [[JSContext alloc] init]; [context evaluatescript:script]; JSValue *func = context[@"textile"]; NSString *text = [NSString stringwithcontentsoffile: [bundle pathforresource:@"sample" oftype:@ textile"] encoding:nsutf8stringencoding error:nil]; NSLog(@"%@", [func callwitharguments:@[text]]);

EvernoteMacEvernoteUI ["Jack Hirsch":https://twitter.com/Jackolicious] h3. ["lesamoureuses":https://twitter.com/lesamoureuses] ["huin":https://twitter.com/huin] ["myb":https://twitter.com/myb] ["nun_":https://twitter.com/nun_] ["KohsakuNishida":https://twitter.com/KohsakuNishida] ["":https://www.facebook.com/hiroki.with.omnia] * 12:30* **** VOYAGE GROUP (8-16 8F)

<p>evernotemacevernoteui <a href="https://twitter.com/jackolicious">jack Hirsch</a><br /> </p> <h3></h3> <p> </p> <p><a href="https://twitter.com/lesamoureuses">lesamoureuses</a><br /> <a href="https://twitter.com/huin">huin</a><br /> <a href="https://twitter.com/myb">myb</a><br /> <a href="https://twitter.com/nun_">nun_</a><br /> <a href="https://twitter.com/kohsakunishida">kohsakunishida</a><br /> <a href="https://www.facebook.com/hiroki.with.omnia"></a> </p> <p><strong> 12:30</strong><br /> <b></b><br /> <span class="caps">voyage</span> <span class="caps">group</ span><br /> (8-16 8F)</p>

@protocol JSUIWindow <JSExport> @property (nonatomic) CGRect frame; @property (nonatomic) UIColor *backgroundcolor; + (id)new; - (void)makekeyandvisible; @end

@interface JSUIWindow : UIWindow <JSUIWindow> @end @implementation JSUIWindow @end

JSContext *context = [[JSContext alloc] init]; context[@"jsuiwindow"] = [JSUIWindow class]; JSContext *context = [[JSContext alloc] init]; context[@"jsuiwindow"] = [JSUIWindow class]; [context evaluatescript:@"var window = JSUIWindow.new();"]; JSValue *value = context[@"window"]; NSLog(@"%@", value.toobject);

class_addprotocol([uiwindow class], @protocol(jsuiwindow)); JSContext *context = [[JSContext alloc] init]; context[@"uiwindow"] = [UIWindow class]; [context evaluatescript:@"var window = UIWindow.new();"]; JSValue *value = context[@"window"]; NSLog(@"%@", value.toobject);

static void setup(jscontext *context) { const char *prefix = "JSUI"; unsigned int numberofclasses; Class *classes = objc_copyclasslist(&numberofclasses); for (unsigned int i = 0; i < numberofclasses; i++) { Class cls = classes[i]; const char *classname = class_getname(cls); NSString *name = @(classname); char protocolname[512]; snprintf(protocolname, sizeof(protocolname), "%s%s", prefix, classname); Protocol *proto = objc_allocateprotocol(protocolname); traverce_class(proto, cls); protocol_addprotocol(proto, @protocol(jsexport)); } objc_registerprotocol(proto); class_addprotocol(cls, proto); context[name] = cls; } free(classes);

@protocol JSBUIView; @protocol JSBUIAlertView <JSExport, JSBUIView> @property (nonatomic, readonly) NSInteger numberofbuttons; @property (nonatomic, readonly, getter = isvisible) BOOL visible; @property (nonatomic) NSInteger cancelbuttonindex; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; @property (nonatomic, assign) id delegate; @property (nonatomic, assign) UIAlertViewStyle alertviewstyle; @property (nonatomic, readonly) NSInteger firstotherbuttonindex; - (id)initwithtitle:(nsstring *)title message:(nsstring *)message delegate:(id)delegate cancelbuttontitle:(nsstring *)cancelbuttontitle otherbuttontitles:(nsstring *)otherbuttontitles,...; - (NSInteger)addButtonWithTitle:(NSString *)title; - (NSString *)buttontitleatindex:(nsinteger)buttonindex; - (void)show; - (void)dismisswithclickedbuttonindex:(nsinteger)buttonindex animated: (BOOL)animated; - (UITextField *)textfieldatindex:(nsinteger)textfieldindex; #pragma clang diagnostic pop @end

@protocol JSBUIView <JSExport, JSBUIResponder> @property (nonatomic, getter = isopaque) BOOL opaque; @property (nonatomic) CGRect frame; @property (nonatomic, getter = ishidden) BOOL hidden; @property (nonatomic) BOOL autoresizessubviews; @property (nonatomic, readonly, copy) NSArray *subviews; + (Class)layerClass; + (void)beginanimations:(nsstring *)animationid context:(void *)context; + (void)commitanimations;

@protocol JSBNSObject <JSExport, NSObject> - (BOOL)isEqual:(id)object; - (NSUInteger)hash; - (Class)superclass; - (Class)class; - (BOOL)isProxy; - (BOOL)isKindOfClass:(Class)aClass; - (BOOL)isMemberOfClass:(Class)aClass; - (BOOL)conformsToProtocol:(Protocol *)aprotocol; - (NSString *)description; - (NSString *)debugdescription; + (void)load; + (void)initialize; - (id)init; + (id)new; + (id)allocwithzone:(struct _NSZone *)zone;

JSContext *context = [JSBScriptingSupport globalcontext]; [context addscriptingsupport:@ AssetsLibrary"]; [context addscriptingsupport:@"accounts"]; [context addscriptingsupport:@"social"]; [context addscriptingsupport:@ MapKit"];

[context evaluatescript: @"var window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen().bounds);" @"window.backgroundcolor = UIColor.whiteColor();" @"" @"var navigationcontroller = UINavigationController.new();" @"" @"var tableviewcontroller = UITableViewController.new();" @"tableviewcontroller.navigationitem.title = 'JavaScriptBridge';" @"navigationcontroller.viewcontrollers = [tableviewcontroller];" @"" @"window.rootviewcontroller = navigationcontroller;" @"" @"window.makekeyandvisible();" @"" @"var alertview = UIAlertView.new();" @"alertview.message = 'Hello JavaScriptBridge';" @"alertview.addbuttonwithtitle('ok');" @"alertview.show();" ];

UISlider *slider = [[UISlider alloc] initwithframe:frame]; slider.backgroundcolor = [UIColor clearcolor]; slider.minimumvalue = 0.0; slider.maximumvalue = 100.0; slider.continuous = YES; slider.value = 50.0; var slider = UISlider.alloc().initWithFrame(frame); slider.backgroundcolor = UIColor.clearColor(); slider.minimumvalue = 0.0; slider.maximumvalue = 100.0; slider.continuous = true; slider.value = 50.0;

UIWindow *window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; var window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen().bounds);

UIView *view = [UIView new]; view.frame = CGRectMake(20, 80, 280, 80); CGFloat x = view.frame.origin.x; CGFloat width = view.frame.size.width; var view = UIView.new(); view.frame = {x: 20, y: 80, width: 280, height: 80}; var x = view.frame.x; var width = view.frame.width;

var MainViewController = JSB.defineClass('MainViewController : UITableViewController', { // Instance Method Definitions viewdidload: function() { self.navigationitem.title = 'UICatalog'; }, viewwillappear: function(animated) { self.tableview.reloaddata(); } }, { // Class Method Definitions attemptrotationtodeviceorientation: function() {... } });

Class cls = objc_allocateclasspair(nsclassfromstring(parentclassname), classname.utf8string, 0); objc_registerclasspair(cls); Class superclass = class_getsuperclass(cls); if (superclass) { setupforwardingimplementations(cls, superclass, instancemembers, staticmembers); } NSString *types; BOOL result; Class metaclass = objc_getmetaclass(classname.utf8string); types = [NSString stringwithformat: @"%s%s%s%s", @encode(nsmethodsignature), @encode(id), @encode(sel), @encode(sel)]; result = class_addmethod(cls, @selector(methodsignatureforselector:), (IMP)methodSignatureForSelector, types.utf8string); result = class_addmethod(metaclass, @selector(methodsignatureforselector:), (IMP)methodSignatureForSelector, types.utf8string); types = [NSString stringwithformat: @"%s%s%s%s", @encode(void), @encode(id), @encode(sel), @encode(nsinvocation)]; result = class_addmethod(cls, @selector(forwardinvocation:), (IMP)forwardInvocation, types.utf8string); result = class_addmethod(metaclass, @selector(forwardinvocation:), (IMP)forwardInvocation, types.utf8string); types = [NSString stringwithformat: @"%s%s%s%s", @encode(bool), @encode(id), @encode(sel), @encode(sel)]; result = class_addmethod(cls, @selector(respondstoselector:), (IMP)respondsToSelector, types.utf8string); result = class_addmethod(metaclass, @selector(respondstoselector:), (IMP)respondsToSelector, types.utf8string); for (NSString *protocol in [protocols componentsseparatedbystring:@","]) { class_addprotocol(cls, NSProtocolFromString([protocol stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]])); } class_addprotocol(cls, @protocol(jsbnsobject)); NSString *key = manglednamefromclass(cls); globalcontext[key] = cls; globalcontext[key][jsbinstancememberskey] = instancemembers; globalcontext[key][jsbstaticmemberskey] = staticmembers; return cls;

Class cls = objc_allocateclasspair(nsclassfromstring(parentclassname), classname.utf8string, 0); objc_registerclasspair(cls);

NSString *types; BOOL result; types = [NSString stringwithformat: @ %s%s%s%s", @encode(nsmethodsignature), @encode(id), @encode(sel), @encode(sel)]; result = class_addmethod(cls, @selector(methodsignatureforselector:), (IMP)methodSignatureForSelector, types.utf8string);

NSMethodSignature *methodsignatureforselector(id self, SEL _cmd, SEL selector) { NSMethodSignature *methodsignature = nil; Class cls = object_getclass(self); if (class_ismetaclass(cls)) { methodsignature = [cls instancemethodsignatureforselector:selector]; if (methodsignature) { return methodsignature; } } else { methodsignature = [cls instancemethodsignatureforselector:selector]; if (methodsignature) { return methodsignature; } } NSUInteger numberofarguments = [[NSStringFromSelector(selector) componentsseparatedbystring:@":"] count] - 1; return [NSMethodSignature signaturewithobjctypes:[[@"@@:" stringbypaddingtolength:numberofarguments + 3 withstring:@"@" startingatindex:0] UTF8String]]; }

BOOL respondstoselector(id self, SEL _cmd, SEL selector) { NSString *propertyname = propertynamefromselector(selector); JSValue *function = propertyforobject(self, propertyname); } return function.isundefined;

void forwardinvocation(id self, SEL _cmd, NSInvocation *invocation) { JSContext *context = [JSBScriptingSupport globalcontext]; if ([[self superclass] instancesrespondtoselector:invocation.selector]) { invokesuper(invocation); } id currentself = context[@"self"]; context[@"self"] = self; NSString *propertyname = propertynamefromselector(invocation.selector); JSValue *function = propertyforobject(self, propertyname); if (function.isundefined) { NSArray *arguments = extractarguments(invocation); JSValue *returnvalue = [function callwitharguments:arguments]; } setreturnvalue(returnvalue, invocation); } context[@"self"] = currentself;

NSString *types; BOOL result; Class metaclass = objc_getmetaclass(classname.utf8string); types = [NSString stringwithformat: @"%s%s%s%s", @encode(nsmethodsignature), @encode(id), @encode(sel), @encode(sel)]; result = class_addmethod(metaclass, @selector(methodsignatureforselector:), (IMP)methodSignatureForSelector, types.utf8string);

JSValue *propertyforobject(id obj, NSString *propertyname) { JSContext *context = [JSBScriptingSupport globalcontext]; JSValue *properties = nil; Class cls = object_getclass(obj); if (class_ismetaclass(cls)) { properties = context[manglednamefromclass(obj)][jsbstaticmemberskey]; } else { properties = context[manglednamefromclass(cls)][jsbinstancememberskey]; } } return properties[propertyname];

unsigned int numberofinstancemethods = 0; Method *instancemethods = class_copymethodlist(cls, &numberofinstancemethods); for (unsigned int i = 0; i < numberofinstancemethods; i++) { Method method = instancemethods[i]; struct objc_method_description *description = method_getdescription(method); NSString *propertyname = propertynamefromselector(description->name); JSValue *function = instancefunctions[propertyname]; if (function.isundefined) { class_addmethod(targetclass, description->name, _objc_msgforward, description->types); } } if (instancemethods) { free(instancemethods); }

class_addmethod(targetclass, description->name, _objc_msgforward, description->types);

OBJC_EXPORT id _objc_msgforward(id receiver, SEL sel,...) OSX_AVAILABLE_STARTING( MAC_10_0, IPHONE_2_0);

void forwardinvocation(id self, SEL _cmd, NSInvocation *invocation) { JSContext *context = [JSBScriptingSupport globalcontext]; if ([[self superclass] instancesrespondtoselector:invocation.selector]) { invokesuper(invocation); } id currentself = context[@"self"]; context[@"self"] = self; NSString *propertyname = propertynamefromselector(invocation.selector); JSValue *function = propertyforobject(self, propertyname); if (function.isundefined) { NSArray *arguments = extractarguments(invocation); JSValue *returnvalue = [function callwitharguments:arguments]; } setreturnvalue(returnvalue, invocation); } context[@"self"] = currentself;

var ButtonsViewController = JSB.require('buttonsViewController'); var ControlsViewController = JSB.require('controlsViewController'); var WebViewController = JSB.require('webViewController'); var MapViewController = JSB.require('mapViewController'); var MainViewController = JSB.defineClass('MainViewController : UITableViewController', { viewdidload: function() { self.navigationitem.title = 'UICatalog';... }); JSB.exports = MainViewController;