{"action":"created","comment":{"url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/comments/50240905","id":50240905,"diff_hunk":"@@ -146,8 +148,95 @@ static void writeAdapter(ExecState* execState, const JSValue& value, void* buffe\n     visitor.append(constructor->_initializers.begin(), constructor->_initializers.end());\n }\n \n+static WTF::String computeInitializerJSName(ExecState* execState, JSFinalObject* initializer, MarkedArgumentBuffer& arguments) {\n+    PropertyNameArray properties(execState, PropertyNameMode::Strings);\n+    initializer->getOwnPropertyNames(initializer, execState, properties, EnumerationMode(DontEnumPropertiesMode::Exclude, JSObjectPropertiesMode::Include));\n+\n+    VM& vm = execState->vm();\n+    WTF::StringBuilder builder;\n+    builder.reserveCapacity(32);\n+    for (auto& property : properties) {\n+        const WTF::String& propertyString = property.string();\n+        const WTF::String firstCharacter = propertyString.substringSharingImpl(0, 1).upper();\n+        const WTF::String rest = propertyString.substringSharingImpl(1);\n+\n+        builder.append(firstCharacter);\n+        builder.append(rest);\n+        arguments.append(initializer->getDirect(vm, property));\n+    }\n+\n+    return builder.toString();\n+}\n+\n+static JSValue getInitializerForSwiftStyleConstruction(ExecState* execState, JSValue prototype, WTF::String jsName) {\n+    static WTF::String initWith(\"initWith\", WTF::String::ConstructFromLiteral);\n+    static WTF::String init(\"init\", WTF::String::ConstructFromLiteral);\n+    static WTF::String error(\"Error\", WTF::String::ConstructFromLiteral);\n+\n+    JSValue value;\n+#define RETURN_IF_CELL if (value.isCell()) return value\n+    \n+    if (jsName.isEmpty()) {\n+        return value;\n+    }\n+\n+    value = prototype.get(execState, Identifier::fromString(execState, WTF::String(initWith + jsName)));\n+    RETURN_IF_CELL;\n+\n+    value = prototype.get(execState, Identifier::fromString(execState, WTF::String(initWith + jsName + error)));\n+    RETURN_IF_CELL;\n+\n+    value = prototype.get(execState, Identifier::fromString(execState, WTF::String(init + jsName)));\n+    RETURN_IF_CELL;\n+\n+    value = prototype.get(execState, Identifier::fromString(execState, WTF::String(init + jsName + error)));\n+    RETURN_IF_CELL;\n+\n+    return JSValue();\n+}\n+\n static EncodedJSValue JSC_HOST_CALL constructObjCClass(ExecState* execState) {\n     ObjCConstructorBase* constructor = jsCast<ObjCConstructorBase*>(execState->callee());\n+\n+    if (execState->argumentCount() <= 1) {\n+        MarkedArgumentBuffer initializerArguments;\n+        JSValue initializer;\n+        if (JSFinalObject* argument = jsDynamicCast<JSFinalObject*>(execState->argument(0))) {\n+            initializer = getInitializerForSwiftStyleConstruction(execState, constructor->instancesStructure()->storedPrototype(), computeInitializerJSName(execState, argument, initializerArguments));\n+        } else if (execState->argumentCount() == 0) {\n+            initializer = constructor->instancesStructure()->storedPrototype().get(execState, Identifier::fromString(execState, \"init\"));\n+        } else {\n+            goto new_legacy;\n+        }\n+\n+        if (initializer && initializer.isCell()) {","path":"src/NativeScript/ObjC/Constructor/ObjCConstructorBase.mm","position":74,"original_position":74,"commit_id":"e1471b85b7e708506f8687d4709ffcca06883cdc","original_commit_id":"e1471b85b7e708506f8687d4709ffcca06883cdc","user":{"login":"fealebenpae","id":289915,"avatar_url":"https://avatars.githubusercontent.com/u/289915?v=3","gravatar_id":"","url":"https://api.github.com/users/fealebenpae","html_url":"https://github.com/fealebenpae","followers_url":"https://api.github.com/users/fealebenpae/followers","following_url":"https://api.github.com/users/fealebenpae/following{/other_user}","gists_url":"https://api.github.com/users/fealebenpae/gists{/gist_id}","starred_url":"https://api.github.com/users/fealebenpae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fealebenpae/subscriptions","organizations_url":"https://api.github.com/users/fealebenpae/orgs","repos_url":"https://api.github.com/users/fealebenpae/repos","events_url":"https://api.github.com/users/fealebenpae/events{/privacy}","received_events_url":"https://api.github.com/users/fealebenpae/received_events","type":"User","site_admin":false},"body":"I'm strongly in favor of removing the now-legacy constructor resolution in a couple of releases - it hardly ever works and is _slow_. Not to mention the enormous infrastructure required to support it.","created_at":"2016-01-20T11:03:21Z","updated_at":"2016-01-20T11:03:21Z","html_url":"https://github.com/NativeScript/ios-runtime/pull/476#discussion_r50240905","pull_request_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476","_links":{"self":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/comments/50240905"},"html":{"href":"https://github.com/NativeScript/ios-runtime/pull/476#discussion_r50240905"},"pull_request":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476"}}},"pull_request":{"url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476","id":56068354,"html_url":"https://github.com/NativeScript/ios-runtime/pull/476","diff_url":"https://github.com/NativeScript/ios-runtime/pull/476.diff","patch_url":"https://github.com/NativeScript/ios-runtime/pull/476.patch","issue_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/476","number":476,"state":"open","locked":false,"title":"Swift-style initializers","user":{"login":"fealebenpae","id":289915,"avatar_url":"https://avatars.githubusercontent.com/u/289915?v=3","gravatar_id":"","url":"https://api.github.com/users/fealebenpae","html_url":"https://github.com/fealebenpae","followers_url":"https://api.github.com/users/fealebenpae/followers","following_url":"https://api.github.com/users/fealebenpae/following{/other_user}","gists_url":"https://api.github.com/users/fealebenpae/gists{/gist_id}","starred_url":"https://api.github.com/users/fealebenpae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fealebenpae/subscriptions","organizations_url":"https://api.github.com/users/fealebenpae/orgs","repos_url":"https://api.github.com/users/fealebenpae/repos","events_url":"https://api.github.com/users/fealebenpae/events{/privacy}","received_events_url":"https://api.github.com/users/fealebenpae/received_events","type":"User","site_admin":false},"body":"This patch augments the JavaScript constructability of Objective-C classes. Constructor functions for Objective-C classes now support initialization via the Swift-style named parameter syntax which mimics Swift's initializer syntax.\r\n\r\nExamples:\r\n`NSURL.alloc().initWithString(aString)` becomes `new NSURL({ string: aString })`\r\n`NSURL.alloc().initFileURLWithPath(aString)` becomes `new NSURL({ fileURLWithPath: aString })`\r\n`NSString.alloc().initWithContentsOfFileEncodingError(aString, anEncoding)` becomes `new NSString({ contentsOfFile: aString, encoding: anEncoding })`","created_at":"2016-01-14T17:40:10Z","updated_at":"2016-01-20T11:03:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65f1fa0d3f3da63d0799732c39c35550f18bbe5d","assignee":{"login":"fealebenpae","id":289915,"avatar_url":"https://avatars.githubusercontent.com/u/289915?v=3","gravatar_id":"","url":"https://api.github.com/users/fealebenpae","html_url":"https://github.com/fealebenpae","followers_url":"https://api.github.com/users/fealebenpae/followers","following_url":"https://api.github.com/users/fealebenpae/following{/other_user}","gists_url":"https://api.github.com/users/fealebenpae/gists{/gist_id}","starred_url":"https://api.github.com/users/fealebenpae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fealebenpae/subscriptions","organizations_url":"https://api.github.com/users/fealebenpae/orgs","repos_url":"https://api.github.com/users/fealebenpae/repos","events_url":"https://api.github.com/users/fealebenpae/events{/privacy}","received_events_url":"https://api.github.com/users/fealebenpae/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/NativeScript/ios-runtime/milestones/12","html_url":"https://github.com/NativeScript/ios-runtime/milestones/1.6.0","labels_url":"https://api.github.com/repos/NativeScript/ios-runtime/milestones/12/labels","id":1430835,"number":12,"title":"1.6.0","description":"","creator":{"login":"atanasovg","id":5878999,"avatar_url":"https://avatars.githubusercontent.com/u/5878999?v=3","gravatar_id":"","url":"https://api.github.com/users/atanasovg","html_url":"https://github.com/atanasovg","followers_url":"https://api.github.com/users/atanasovg/followers","following_url":"https://api.github.com/users/atanasovg/following{/other_user}","gists_url":"https://api.github.com/users/atanasovg/gists{/gist_id}","starred_url":"https://api.github.com/users/atanasovg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atanasovg/subscriptions","organizations_url":"https://api.github.com/users/atanasovg/orgs","repos_url":"https://api.github.com/users/atanasovg/repos","events_url":"https://api.github.com/users/atanasovg/events{/privacy}","received_events_url":"https://api.github.com/users/atanasovg/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":25,"state":"open","created_at":"2015-11-26T09:57:30Z","updated_at":"2016-01-19T12:11:17Z","due_on":"2016-02-16T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476/commits","review_comments_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476/comments","review_comment_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/476/comments","statuses_url":"https://api.github.com/repos/NativeScript/ios-runtime/statuses/e1471b85b7e708506f8687d4709ffcca06883cdc","head":{"label":"NativeScript:fealebenpae/swift-style-constructors","ref":"fealebenpae/swift-style-constructors","sha":"e1471b85b7e708506f8687d4709ffcca06883cdc","user":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"repo":{"id":29675401,"name":"ios-runtime","full_name":"NativeScript/ios-runtime","owner":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NativeScript/ios-runtime","description":"iOS runtime for NativeScript (based on JavaScriptCore)","fork":false,"url":"https://api.github.com/repos/NativeScript/ios-runtime","forks_url":"https://api.github.com/repos/NativeScript/ios-runtime/forks","keys_url":"https://api.github.com/repos/NativeScript/ios-runtime/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NativeScript/ios-runtime/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NativeScript/ios-runtime/teams","hooks_url":"https://api.github.com/repos/NativeScript/ios-runtime/hooks","issue_events_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/events{/number}","events_url":"https://api.github.com/repos/NativeScript/ios-runtime/events","assignees_url":"https://api.github.com/repos/NativeScript/ios-runtime/assignees{/user}","branches_url":"https://api.github.com/repos/NativeScript/ios-runtime/branches{/branch}","tags_url":"https://api.github.com/repos/NativeScript/ios-runtime/tags","blobs_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/refs{/sha}","trees_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NativeScript/ios-runtime/statuses/{sha}","languages_url":"https://api.github.com/repos/NativeScript/ios-runtime/languages","stargazers_url":"https://api.github.com/repos/NativeScript/ios-runtime/stargazers","contributors_url":"https://api.github.com/repos/NativeScript/ios-runtime/contributors","subscribers_url":"https://api.github.com/repos/NativeScript/ios-runtime/subscribers","subscription_url":"https://api.github.com/repos/NativeScript/ios-runtime/subscription","commits_url":"https://api.github.com/repos/NativeScript/ios-runtime/commits{/sha}","git_commits_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/commits{/sha}","comments_url":"https://api.github.com/repos/NativeScript/ios-runtime/comments{/number}","issue_comment_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/comments{/number}","contents_url":"https://api.github.com/repos/NativeScript/ios-runtime/contents/{+path}","compare_url":"https://api.github.com/repos/NativeScript/ios-runtime/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NativeScript/ios-runtime/merges","archive_url":"https://api.github.com/repos/NativeScript/ios-runtime/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NativeScript/ios-runtime/downloads","issues_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues{/number}","pulls_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls{/number}","milestones_url":"https://api.github.com/repos/NativeScript/ios-runtime/milestones{/number}","notifications_url":"https://api.github.com/repos/NativeScript/ios-runtime/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NativeScript/ios-runtime/labels{/name}","releases_url":"https://api.github.com/repos/NativeScript/ios-runtime/releases{/id}","created_at":"2015-01-22T11:21:31Z","updated_at":"2016-01-11T09:48:50Z","pushed_at":"2016-01-20T09:46:58Z","git_url":"git://github.com/NativeScript/ios-runtime.git","ssh_url":"git@github.com:NativeScript/ios-runtime.git","clone_url":"https://github.com/NativeScript/ios-runtime.git","svn_url":"https://github.com/NativeScript/ios-runtime","homepage":"http://docs.nativescript.org/runtimes/ios","size":217909,"stargazers_count":87,"watchers_count":87,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":59,"forks":17,"open_issues":59,"watchers":87,"default_branch":"master"}},"base":{"label":"NativeScript:master","ref":"master","sha":"dfb827ca3a8b656408c72248e7d0df7063f1aae7","user":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"repo":{"id":29675401,"name":"ios-runtime","full_name":"NativeScript/ios-runtime","owner":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NativeScript/ios-runtime","description":"iOS runtime for NativeScript (based on JavaScriptCore)","fork":false,"url":"https://api.github.com/repos/NativeScript/ios-runtime","forks_url":"https://api.github.com/repos/NativeScript/ios-runtime/forks","keys_url":"https://api.github.com/repos/NativeScript/ios-runtime/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NativeScript/ios-runtime/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NativeScript/ios-runtime/teams","hooks_url":"https://api.github.com/repos/NativeScript/ios-runtime/hooks","issue_events_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/events{/number}","events_url":"https://api.github.com/repos/NativeScript/ios-runtime/events","assignees_url":"https://api.github.com/repos/NativeScript/ios-runtime/assignees{/user}","branches_url":"https://api.github.com/repos/NativeScript/ios-runtime/branches{/branch}","tags_url":"https://api.github.com/repos/NativeScript/ios-runtime/tags","blobs_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/refs{/sha}","trees_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NativeScript/ios-runtime/statuses/{sha}","languages_url":"https://api.github.com/repos/NativeScript/ios-runtime/languages","stargazers_url":"https://api.github.com/repos/NativeScript/ios-runtime/stargazers","contributors_url":"https://api.github.com/repos/NativeScript/ios-runtime/contributors","subscribers_url":"https://api.github.com/repos/NativeScript/ios-runtime/subscribers","subscription_url":"https://api.github.com/repos/NativeScript/ios-runtime/subscription","commits_url":"https://api.github.com/repos/NativeScript/ios-runtime/commits{/sha}","git_commits_url":"https://api.github.com/repos/NativeScript/ios-runtime/git/commits{/sha}","comments_url":"https://api.github.com/repos/NativeScript/ios-runtime/comments{/number}","issue_comment_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues/comments{/number}","contents_url":"https://api.github.com/repos/NativeScript/ios-runtime/contents/{+path}","compare_url":"https://api.github.com/repos/NativeScript/ios-runtime/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NativeScript/ios-runtime/merges","archive_url":"https://api.github.com/repos/NativeScript/ios-runtime/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NativeScript/ios-runtime/downloads","issues_url":"https://api.github.com/repos/NativeScript/ios-runtime/issues{/number}","pulls_url":"https://api.github.com/repos/NativeScript/ios-runtime/pulls{/number}","milestones_url":"https://api.github.com/repos/NativeScript/ios-runtime/milestones{/number}","notifications_url":"https://api.github.com/repos/NativeScript/ios-runtime/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NativeScript/ios-runtime/labels{/name}","releases_url":"https://api.github.com/repos/NativeScript/ios-runtime/releases{/id}","created_at":"2015-01-22T11:21:31Z","updated_at":"2016-01-11T09:48:50Z","pushed_at":"2016-01-20T09:46:58Z","git_url":"git://github.com/NativeScript/ios-runtime.git","ssh_url":"git@github.com:NativeScript/ios-runtime.git","clone_url":"https://github.com/NativeScript/ios-runtime.git","svn_url":"https://github.com/NativeScript/ios-runtime","homepage":"http://docs.nativescript.org/runtimes/ios","size":217909,"stargazers_count":87,"watchers_count":87,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":59,"forks":17,"open_issues":59,"watchers":87,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476"},"html":{"href":"https://github.com/NativeScript/ios-runtime/pull/476"},"issue":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/issues/476"},"comments":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/issues/476/comments"},"review_comments":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476/comments"},"review_comment":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/pulls/476/commits"},"statuses":{"href":"https://api.github.com/repos/NativeScript/ios-runtime/statuses/e1471b85b7e708506f8687d4709ffcca06883cdc"}}}}