2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "path-wrapper.h"
22 #include <animation/path-api.h>
24 #include <dali-wrapper.h>
25 #include <shared/object-template-helper.h>
36 const ApiFunction PathFunctions[]=
38 { "GenerateControlPoints", PathApi::GenerateControlPoints },
39 { "AddPoint", PathApi::AddPoint },
40 { "AddControlPoint", PathApi::AddControlPoint },
41 { "Sample", PathApi::Sample }
44 const unsigned int PathFunctionTableCount = sizeof(PathFunctions)/sizeof(PathFunctions[0]);
48 PathWrapper::PathWrapper( Path path, GarbageCollectorInterface& gc )
49 :HandleWrapper( BaseWrappedObject::PATH, path, gc ),
54 v8::Handle<v8::ObjectTemplate> PathWrapper::MakePathTemplate( v8::Isolate* isolate )
56 v8::EscapableHandleScope handleScope( isolate );
58 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
59 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
61 // add our function properties
62 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PathFunctions, PathFunctionTableCount );
64 // property handle intercepts property getters and setters and signals
65 HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
67 return handleScope.Escape( objTemplate );
70 v8::Handle<v8::Object> PathWrapper::WrapPath( v8::Isolate* isolate, Path path )
72 v8::EscapableHandleScope handleScope( isolate );
73 v8::Local<v8::ObjectTemplate> objectTemplate;
75 objectTemplate = MakePathTemplate( isolate );
77 // create an instance of the template
78 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
80 // create teh actor object
81 PathWrapper* pointer = new PathWrapper( path, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
83 // assign the JavaScript object to the wrapper.
84 // This also stores Dali object, in an internal field inside the JavaScript object.
85 pointer->SetJavascriptObject( isolate, localObject );
87 return handleScope.Escape( localObject );
90 Path PathWrapper::GetPath()
96 * Create an initialized Path handle.
101 void PathWrapper::NewPath( const v8::FunctionCallbackInfo< v8::Value >& args)
103 v8::Isolate* isolate = args.GetIsolate();
104 v8::HandleScope handleScope( isolate );
106 if( !args.IsConstructCall() )
108 DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
113 Path path = Path::New();
114 v8::Local<v8::Object> localObject = WrapPath( isolate, path );
115 args.GetReturnValue().Set( localObject );
119 } // namespace V8Plugin