Skip to content

Instantly share code, notes, and snippets.

@tondrej
Created November 11, 2018 21:23
Show Gist options
  • Save tondrej/193fd399d640b9e01dd4c717bc04bf44 to your computer and use it in GitHub Desktop.
Save tondrej/193fd399d640b9e01dd4c717bc04bf44 to your computer and use it in GitHub Desktop.
Rectangle
type
TRectangle = class(TNativeObject)
class procedure InitializeInstance(AInstance: JsValueRef; Args: PJsValueRef; ArgCount: Word); override;
class function InitializePrototype(AConstructor: JsValueRef): JsValueRef; override;
end;
class procedure TRectangle.InitializeInstance(AInstance: JsValueRef; Args: PJsValueRef; ArgCount: Word);
var
ArgsArray: PJsValueRefArray absolute Args;
ShapeCtr: JsValueRef;
begin
// Shape.call(x, y);
ShapeCtr := JsGetProperty(JsGlobal, 'Shape');
JsCallFunction(ShapeCtr, [AInstance, ArgsArray^[0], ArgsArray^[1]]);
// this.w = w;
JsSetProperty(AInstance, UnicodeString('w'), ArgsArray^[2]);
// this.h = h;
JsSetProperty(AInstance, UnicodeString('h'), ArgsArray^[3]);
end;
class function TRectangle.InitializePrototype(AConstructor: JsValueRef): JsValueRef;
var
ShapeCtr, ShapePrototype: JsValueRef;
begin
ShapeCtr := JsGetProperty(JsGlobal, 'Shape');
ShapePrototype := JsGetProperty(ShapeCtr, 'prototype');
// Rectangle.prototype = Object.create(Shape.prototype);
Result := JsCreateObject(ShapePrototype);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment