
ObjectTemplateBuilder (and Wrappable) allow setting functions that are exposed in JS and then forwarded to the type in C++. If these are C++ member functions, the context object is retrieved by looking at the this-object in JavaScript, and trying to convert that to the underlying C++ type (which will succeed if it was called on the V8 object created by the Wrappable). However, these member functions will fail if the JS function is called on an improper this-object (including null and undefined). This means that doing things like: var obj = getObj(); // Some object from a Wrappable var doFoo = obj.doFoo; doFoo(); will fail because it's applied on an invalid this-object (undefined), and the conversion will fail. This makes sense, but unfortunatley the error gin throws in this case is unhelpful: "Uncaught TypeError: Error processing argument at index -1, conversion failure from undefined" Instead, allow Wrappables and ObjectTemplateBuilders to specify a type name, which will be surfaced in these errors to provide guidance to developers. Update the error message to either include the type name or to match the error message used in similar circumstances in blink ("Illegal invocation"). The new error messages will only be shown for failures in converting to the context object, not for failure to convert subsequent arguments. Bug: <File One> Change-Id: I515a17e92992bfcb709b97455b9167b350e931f2 Reviewed-on: https://chromium-review.googlesource.com/987304 Commit-Queue: Devlin <rdevlin.cronin@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Cr-Commit-Position: refs/heads/master@{#549219}
Gin - Lightweight bindings for V8
This directory contains Gin, a set of utilities to make working with V8 easier.
Here are some of the key bits:
-
converter.h: Templatized JS ↔ C++ conversion routines for many common C++ types. You can define your own by specializing Converter.
-
function_template.h: Create JavaScript functions that dispatch to any C++ function, member function pointer, or base::Callback.
-
object_template_builder.h: A handy utility for creation of v8::ObjectTemplate.
-
wrappable.h: Base class for C++ classes that want to be owned by the V8 GC. Wrappable objects are automatically deleted when GC discovers that nothing in the V8 heap refers to them. This is also an easy way to expose C++ objects to JavaScript.
-
runner.h: Create script contexts and run code in them.
-
module_runner_delegate.h: A delegate for runner that implements a subset of the AMD module specification. Also see modules/ with some example modules.