{"id":23841896,"url":"https://github.com/web-atoms/xamarin-v8","last_synced_at":"2025-09-07T17:32:24.650Z","repository":{"id":46901266,"uuid":"246768326","full_name":"web-atoms/xamarin-v8","owner":"web-atoms","description":"V8 Bindings for Xamarin for Android","archived":false,"fork":false,"pushed_at":"2023-03-02T22:41:44.000Z","size":268357,"stargazers_count":8,"open_issues_count":16,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T04:09:27.836Z","etag":null,"topics":["javascript","v8","xamarin-android"],"latest_commit_sha":null,"homepage":"https://www.webatoms.in/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/web-atoms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-12T07:18:33.000Z","updated_at":"2024-02-16T05:16:46.000Z","dependencies_parsed_at":"2023-02-14T22:00:57.308Z","dependency_job_id":null,"html_url":"https://github.com/web-atoms/xamarin-v8","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/web-atoms/xamarin-v8","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-atoms%2Fxamarin-v8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-atoms%2Fxamarin-v8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-atoms%2Fxamarin-v8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-atoms%2Fxamarin-v8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/web-atoms","download_url":"https://codeload.github.com/web-atoms/xamarin-v8/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-atoms%2Fxamarin-v8/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273799627,"owners_count":25170445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","v8","xamarin-android"],"created_at":"2025-01-02T18:21:55.493Z","updated_at":"2025-09-07T17:32:19.630Z","avatar_url":"https://github.com/web-atoms.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NuGet](https://img.shields.io/nuget/v/Xamarin.Android.V8.svg?label=NuGet)](https://www.nuget.org/packages/Xamarin.Android.V8)\n\n# Xamarin V8 Bindings\nV8 Bindings for Xamarin for Android\n\nThough V8 is very heavy, you can try `YantraJS`, very light weight JavaScript engine written in C#.\n\n# NuGet\n```xml\n\u003cPackageReference Include=\"Xamarin.Android.V8\" Version=\"1.4.79\" /\u003e\n```\n# Inspector Protocol Port\nVisual Studio \u003e Tools \u003e Android \u003e Android Adb Command Prompt\n```\nadb forward tcp:9222 tcp:9222\n```\n\nIf you want to change the default 9222 port, you can specify in the parameters.\n\n\n\n# Create Context\n\n```c#\nusing Xamarin.Android.V8;\n\nusing(var context = new JSContext( /*Enable Debugging*/ true)) {\n\n  // you can connect to dev tools by visiting url\n  // devtools://devtools/bundled/inspector.html?experiments=true\u0026v8only=true\u0026ws=127.0.0.1:9222/backend\n  \n  \n\n}\n```\n\n# Create New Global Function\n```c#\ncontext[\"printf\"] = context.CreateFunction(0, (c, a) =\u003e {\n  // first parameter is context isself\n  // second parameter is an array as IJSValue\n  System.Diagnostics.Debug.WriteLine(a[0].ToString());\n  return c.Undefined;\n});\n\n// JS : printf(\"a\");\n```\n\n# Evaluate Script with Location\n```c#\n// script location is useful for debugging\ncontext.Evaluate(scriptText, scriptLocation);\n```\n\n# Navigate Objects\n\n```c#\n   // Object.create() JavaScript Equivalent in c#\n   var obj = context[\"Object\"].InvokeMethod(\"create\");\n```\n\n# Convert Native Objects\nAs V8 Engine has its own representation of native types, you need to create them in order to pass them as parameters for JavaScript methods.\n\n```c#\n   var jsString = context.CreateString(\"TEXT\");\n   var jsNumber = context.CreateNumber(100);\n   \n   context[\"console\"].InvokeMethod(\"log\", jsString);\n   context[\"console\"].InvokeMethod(\"log\", jsNumber);\n```\n\n# Evaluate Template\n\n```c#\n\n   // clr object\n   var s = \"Akash\";\n\n   context.EvaluateTemplate($\"console.log({s})\");\n\n```\n\nThis method serializes every clr object input as IJSValue by doing `Wrap` serialization. You can however serialize and then send object as parameter to templated string. It will store all object in global and evaluate JavaScript, you do not have to worry about the escape as each input is serialized and they are substituted as parameter to placeholders.\n\n# Serialize C# Object\n\nWhen you use method `context.Convert` method to automatically create native JS values from native types, it will only wrap C# custom object, you cannot call any method or access property from JavaScript on wrapped object. This is done to improve performance. So when you pass C# objects in and out, engine will not create methods and properties on them.\n\nIn order to access methods and properties of C# object, you have to serialize them.\n\n```c#\n\n   // you can access all properties, no methods\n   var jsDictObject = context.Marshal( customClrObject , SerializationMode.Copy);\n   \n   // you can access all properties and invoke method as well\n   var jsClrObject = context.Marshal( customClrObject , SerializationMode.Reference);\n\n```\n\n## Serialization Modes\n\n### Copy\nThis method will create a deep copy of CLR Object as dictionary which you can easily access inside JavaScript code. This method will fail if there are self referencing objects in the object graph. This limitation may be removed in future, but right now it will throw an exception.\n\nThis method is also very slow as deep copy operation will take more time.\n\nDeserialization will also be slow as it will completely construct new object with all properties.\n\n### Reference\nKeeps reference along with serialization, every property is serialized as getter/setter, upon deserialization, same object will be returned.\n\nThis method is useful for self referencing objects, but this may cause memory leak if you keep reference in JavaScript and JavaScript garbage collector fails to dispose object.\n\nDeserialization is faster as it simply returns referenced object.\n\n### WeakReference\nSame as Reference but it only keeps weak reference, you will get object disposed if you try to access object in JavaScript and it is disposed in CLR. CLR is very aggressive while disposing objects, so this may not work if you do not keep reference in CLR. This is also recommended method as it will avoid memory leaks.\n\n### Wrap\nThis is default serialization method for any object. Object will simply be wrapped and no methods/properties are exposed.\n\n\n\n\n# Resources\n1. https://kerry.lothrop.de/c-libraries/\n2. https://devblogs.microsoft.com/cppblog/developing-xamarin-android-native-applications/\n3. https://devblogs.microsoft.com/wp-content/uploads/sites/9/2019/02/XamarinNativeExample.zip\n4. https://github.com/rjamesnw/v8dotnet/blob/master/Source/V8.NET-Proxy/ProxyTypes.h\n5. https://devblogs.microsoft.com/cppblog/android-and-ios-development-with-c-in-visual-studio/\n6. https://github.com/lothrop/XamarinNative\n7. https://github.com/xamcat/mobcat-samples/tree/master/cpp_with_xamarin\n8. https://stackoverflow.com/questions/31541451/create-shared-library-from-cpp-files-and-static-library-with-g\n9. https://hyperandroid.com/2020/02/12/compile-v8-arm-arm64-ia32/\n10. https://hyperandroid.com/2020/02/12/android-v8-embedding-guide/\n11. https://hyperandroid.com/2020/02/12/v8-inspector-from-an-embedder-standpoint/\n\n## Other Interesting Projects by NeuroSpeech\n1. [YantraJS - JavaScript engine for .NET with latest features](https://github.com/yantrajs/yantra)\n2. [Entity Access Control](https://github.com/neurospeech/entity-access-control)\n3. [Eternity - Long running workflows with ability to suspend and replay the workflow in future.](https://github.com/neurospeech/eternity)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-atoms%2Fxamarin-v8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweb-atoms%2Fxamarin-v8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-atoms%2Fxamarin-v8/lists"}